Windows Random numbers always the same.

M

MrTholl

Guest
I am to the point where I can kill an enemy and he can kill me but he always kills me first. The random range is always the same for both me and the enemy. I put the player attack variable in the player object and the enemy attack variable in the enemy object. I then call both into the attack button object and set the players and enemys health after taking damge .GS2 Problem 7.png GS2 Problem 8.png
 
J

joakimFF

Guest
At the start of the game call randomize(); in a execute code block
 

samspade

Member
While not immediately apparent, that is in fact what is supposed to happen. Quoting from the manual:

The randomize() function sets the seed to a random value. Should you need to keep a consistent value over a number of runs of a game, you should be using random_set_seed(). Please note, that when using the random number functions in GameMaker: Studio the initial seed is always the same, as this makes tracing errors and debugging far easier. Should you wish to test with true random, you should call this function at the start of your game.

So by default, GMS and GMS2 both essentially use a seed, and randomize() is necessary if you don't want that.

(Personally, I think randomize by default makes more sense as by the time you know or care that it isn't you could easily set your own seed for testing purposes, but that's the way it is.)

Edit:

Sorry I'm new. How to do this?
Just put:

Code:
randomize();
In some object that is called early in the game.
 
M

MrTholl

Guest
GS2 Problem 10.png Gah I just noticed it will only randomize once. Then that will be the number from now on. I call global.player(or enemy)_attack in the attack object.
 

FrostyCat

Redemption Seeker
Gah I just noticed it will only randomize once. Then that will be the number from now on. I call global.player(or enemy)_attack in the attack object.
When you use Set Variable actions or the assignment operator in GML, you are NOT binding the variable to the expression, you are only giving that variable the expression's value at that point in time. Referencing it later won't re-run the expression.

If you want to get different numbers on each tap, you need to put the Get Random Number action on attack_obj's Tap event.
 
Top