Page 1 of 1

problem with randomize and toggleKey

Posted: Thu Mar 19, 2020 2:00 pm
by papainoel14
The random in config folder is probably not randomizing anything because everything is spawned together on the tiled.
Can anyone help with that?

@Edit
how can i make this work on mac?
I don't have a mac to test

function love.keypressed(key, scancode, isrepeat)

if gameState == 0 and scancode == "return" then
gameState = 1
elseif Inventarios.Open == false and scancode == "i" and gameState > 0 then
Inventarios.Open = true
elseif Inventarios.Open == true and scancode == "i" and gameState > 0 then
Inventarios.Open = false
end
end

@edit: https://github.com/NinguemLPJ/games/tre ... inguem_RPG

Re: problem with randomize and toggleKey

Posted: Thu Mar 19, 2020 5:44 pm
by tobiasvl
I don't understand either of your questions. Can you provide a bit more context?

Re: problem with randomize and toggleKey

Posted: Thu Mar 19, 2020 6:03 pm
by papainoel14
https://love2d.org/imgmirrur/QweJywv.mp4
look at the money, it was supposed to be random but always comes the same amount

Re: problem with randomize and toggleKey

Posted: Sat Mar 21, 2020 6:05 am
by bobbyjones
You are setting the coin value in the files scope. Meaning the value is only set when the file is loaded once. You need to set a random value for each individual coin. If you know oop design you are essentially setting a static class property instead of setting a per instance value. To fix this when you create the coins random location also create it's random value and store it in the same table.

Re: problem with randomize and toggleKey

Posted: Sat Mar 21, 2020 11:46 am
by zorg
i looked at their conf.lua as well, and i only saw min and max values defined; i didn't see where they called (love.)math.random. that would help in debugging if that info bit was shared.

Re: problem with randomize and toggleKey

Posted: Sat Mar 21, 2020 12:33 pm
by pgimeno
The OP didn't make it easy to find, but I'm going to guess that the problem is for example here:

https://github.com/NinguemLPJ/games/blo ... oin.lua#L3

The solution is simply to use love.math.random instead of math.random.

Re: problem with randomize and toggleKey

Posted: Sat Mar 21, 2020 8:07 pm
by zorg
pgimeno wrote: Sat Mar 21, 2020 12:33 pm The OP didn't make it easy to find, but I'm going to guess that the problem is for example here:
https://github.com/NinguemLPJ/games/blo ... oin.lua#L3
The solution is simply to use love.math.random instead of math.random.
Yeah i thought about that being the problem and the solution, however, that would only be an issue regarding getting the same random numbers on each startup,but not for consecutive calls which was what i understood was the issue...

but twist #2: that line is indeed the problem, because only one random number is generated and saved into the local, instead of one per object, i'm guessing.

Re: problem with randomize and toggleKey

Posted: Sun Mar 22, 2020 7:18 pm
by papainoel14
I created a function called debug, just to print the number generated below the player, I think I discovered the big problem, I couldn't find a solution so far.

with what you said I managed to solve the problem of being called only once, but it is not yet generated for non-integer numbers

If you help me look for a solution I will be grateful. and I imagine that this way it is easier for you to test your solution without having to try to understand my project


take a look at git again

Last functions of .lua
Ninguem_Extras/Ninguem_functions
debugUpdate(randomMAX, randomMIN) -- just change this function and the numbers inside the main update