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 » Thu Mar 19, 2020 2:00 pm

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 » Thu Mar 19, 2020 5:44 pm

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 » Thu Mar 19, 2020 6:03 pm

https://i.imgur.com/QweJywv
look at the money, it was supposed to be random but always comes the same amount
Ninguem

bobbyjones
Party member
Posts: 728
Joined: Sat Apr 26, 2014 7:46 pm

Re: problem with randomize and toggleKey

Post by bobbyjones » Sat Mar 21, 2020 6:05 am

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.
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.

User avatar
zorg
Party member
Posts: 2995
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: problem with randomize and toggleKey

Post by zorg » Sat Mar 21, 2020 11:46 am

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: 2318
Joined: Sun Oct 18, 2015 2:58 pm

Re: problem with randomize and toggleKey

Post by pgimeno » 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.

User avatar
zorg
Party member
Posts: 2995
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: problem with randomize and toggleKey

Post by zorg » Sat Mar 21, 2020 8:07 pm

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 » Sun Mar 22, 2020 7:18 pm

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: No registered users and 28 guests