problem with randomize and toggleKey

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
papainoel14
Prole
Posts: 10
Joined: Fri Mar 13, 2020 3:59 pm

problem with randomize and toggleKey

Post 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
Last edited by papainoel14 on Fri Mar 20, 2020 7:47 pm, edited 4 times in total.
Ninguem
tobiasvl
Prole
Posts: 29
Joined: Mon Oct 01, 2018 4:58 pm
Location: Norway
Contact:

Re: problem with randomize and toggleKey

Post by tobiasvl »

I don't understand either of your questions. Can you provide a bit more context?
User avatar
papainoel14
Prole
Posts: 10
Joined: Fri Mar 13, 2020 3:59 pm

Re: problem with randomize and toggleKey

Post by papainoel14 »

https://love2d.org/imgmirrur/QweJywv.mp4
look at the money, it was supposed to be random but always comes the same amount
Ninguem
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: problem with randomize and toggleKey

Post 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.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: problem with randomize and toggleKey

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: problem with randomize and toggleKey

Post 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.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: problem with randomize and toggleKey

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
papainoel14
Prole
Posts: 10
Joined: Fri Mar 13, 2020 3:59 pm

Re: problem with randomize and toggleKey

Post 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
Ninguem
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 47 guests