Changing Portrait Game into Landscape breaks Lua or Solar2D?

I have a game running on Android and iOS. Now, I want to make it work for Mac, Windows and Apple TV. So, the first thing I’ve done is change my build.settings portrait settings into landscape as follows:

default = “portrait”,
content = “portrait”,
supported = { “portrait”, “portraitupsidedown”},
default = “landscape”,
content = “landscape”,
supported = { “landscape”,“landscape”}, --also tried with a single “landscape”

Now, I’m getting an error that appears to indicate the math library isn’t working. The game crashes when I attempt to get math.random(100).

This is very strange. Anyone have a clue?

Your orientation names are all wrong. Please see:

Changing orientation doesn’t break Lua or Solar2D, but since you don’t have a single correct supported orientation, that might cause the engine to fail to initialise.

The correct values are:


Thank you so much for the attempt to help me. Based upon your recommendation, I currently have:
orientation =
default = “landscapeLeft”,
content = “landscapeLeft”,
supported = { “landscapeLeft”,“landscapeRight”},

It still doesn’t work. What I had before, in simulator, does bring up the device in a landscape mode (without the Left or Right). So, the orientation appeared properly. But the math library has trouble. Maybe you are onto something, though, about an incorrect orientation that could cause the math library to become confused. So, I need more help. I’m still stuck.

Could you share a simple project that demonstrates your issue?

I’ve never experienced or even heard of something like this happening before, and I have no idea how the math library could be affected orientation changes unless it was explicitly being overwritten somewhere in the code.

@XeduR, thank you for your help. But thanks to help from a friend, I discovered that for some reason, math.random is being called with a “nil” parameter. Not sure why, though. I’ll let you know what I find out.

@XeduR, the problem was that my use of math.random, as a result of having the content width as a larger value than the content height, caused a problem when the first parameter was larger than the second parameter. In other words, randomValue=math.random(width,height) will cause the problem because the width is larger than the height…

To solve, now I’m using randomValue=width+math.random(math.abs(width-height)).

You could also force the smaller dimension to be the first argument and the larger to be the second using:
randomValue=math.random( math.min(width,height), math.max(width, height) )

1 Like

Lua tends to give fairly verbose error messages.

For instance, if you ran math.random(2,1) then you should get a warning: "bad argument #2 to 'random' (interval is empty)", which would be fairly easy to debug.

Based on the initial info that the math library isn’t working, I was expecting something weird to have happened. :smiley:

@XeduR, yes, I think the error message is more confusing than anything. It is the only place in all my code that I use the random function to get a value between two values. Now, I just get a single random value and add it to the base value.