I am almost done with a game I am developing, and everything is working fine on windows.
However when I tested out the game on Android, there were some bugs:
In my game I needed to draw a line from one fixed point to a variable point so I thought of using render.draw_line
On Android: the line isn’t showing
In my game I need to create multiple game objects in different random positions. On windows, it is working perfectly fine
On Android: All objects are being spawned in the same location
Note: I am using the following
math.randomseed(os.time()* 1000000 * math.random() * math.random())
local yPos = math.random(267, 700)
Note: the android device I’m using is Sony Xperia Z2
EDIT: I was able to solve the following issue: The problem was that I was checking for both mouse click and multi-touch event when checking for user input (i.e: if (action_id == hash(“click”)) or (action_id == hash(“touch”)) then) I removed the mouse trigger action and the problem was solved!
Solved issue: In my game there’s an option to buy multiple items, and when the user chooses to do so a message is sent to deduct coins from the player’s coins.
On Android: the message is being sent twice (However, this is working perfectly fine when I tested it in the Defold Editor)
After making the fix you told me to do, the objects are now being spawned at random positions, but every time I launch the game they are spawned at the same exact position, rather than having different positions.
if go.get("/path", "Object1") then
local object1Pos= go.get_position()
local objectxPos= math.random(-10, 1290)
local objectyPos= math.random(267, 700)
object1Pos.x= objectxPos
object1Pos.y= objectyPos
object1Pos.z = 0.5
local component= "#object1Factory"
object1= factory.create(component, object1Pos)
end
this is the init function for the same script:
function init(self)
math.randomseed(os.clock()*100000000000)
end
Note: this is done for multiple objects in the same script
That means your random seed is the same every time. If you’re setting the seed on startup then os.clock() may be the same or very similar every time. Try using os.time() for your seed, or maybe something like: socket.gettime() % 1 * 1000