• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Sprites are the same even though code says not to

J

Joey2bost

Guest
this is very annoying, the jobs or how they work are working but there sprites are always the same.
I am using Game Maker Studio 1.4

all of these are in step events...

code1:
if global.choice == 0
{
global.choice = 1;
}


if global.choice == 1
{
sprite_index = spr_victum;
global.player1_victum = true;
global.player1_killer = false;
}
else
{
sprite_index = spr_killer;
global.player1_killer = true;
global.player1_victum = false;
}


code2:
///double checking to see if player is who
//player 1
if global.player1_killer == true && global.player1_victum == false
{
sprite_index = spr_killer;
}
else if global.player1_killer == false && global.player1_victum == true
{
sprite_index = spr_victum;
}

//player 2
if global.player2_killer == true && global.player2_victum == false
{
sprite_index = spr_killer;
}
else if global.player2_killer == false && global.player2_victum == true
{
sprite_index = spr_victum;
}

//settling the copys debate
if global.player1_killer == true && global.player2_killer == true
{
global.player1_killer = false;
global.player1_victum = true;
}

if global.player1_victum == true && global.player2_victum == true
{
global.player1_killer = true;
global.player1_victum = false;
}


if global.player1_killer == true && global.player1_victum == true
{
global.player1_victum = false;
}

if global.player2_killer == true && global.player2_victum == true
{
global.player2_killer = false;
}



code3:
//player 1
///double checking the sprite for both

if global.player1_killer == true
{
sprite_index = spr_killer;
}

if global.player1_killer == false
{
sprite_index = spr_victum;
}

//player 2
///double checking the sprite for both

if global.player2_killer == true
{
sprite_index = spr_killer;
}

if global.player2_killer == false
{
sprite_index = spr_victum;
}
 
J

Joey2bost

Guest
You are forcing global.choice to always be 1, that's why you get the same result every time. Trace out the first piece and see for yourself.
i have in the creat say choice = irandom(2);
when ever it equals 2 it lets player two be killer
 

FrostyCat

Redemption Seeker
Did you call randomize() exactly once at the beginning of your game? You need to do that or it will be the same every time.

Also, if you are not going to be using 0 in global.choice, set it to irandom_range(1, 2) or choose(1, 2) instead. Don't use a function that may return stuff you don't want and then waste time filtering it out later.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Did you call randomize() exactly once at the beginning of your game? You need to do that or it will be the same every time.
Just to clarify this point... When TESTING your game in GMS the random seed will always be the same to make debugging easier. When the game is compiled this will not be the case and the random functions should work as required. Therefore when testing it is always a good idea to include the randomize function at the start of the game to ensure you get the same behaviour as when the game is compiled. ;)
 

Fern

Member
Hang on a sec. Are you saying that values won't stay the same after a compile?

If that's correct, that is a major bummer, as a user set random seed is commonly used to generate terrain and forests which will then be the same layout on other machines of the same architecture.

Saves having to create massive level files, relying on the non-random nature of random().
random_set_seed() will result in the same randomness each time. So you can save the seed to a file to generate the same results no matter what. However, order of execution is important.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Ummm... Just checking the manual and it doesn't explicitly say it's only when testing and not on compile... Which is possibly an oversight on my part!!! I'm almost 100% sure though that on compile the random functions are true random, and on debug it's a fixed seed....
 

Fern

Member
Ummm... Just checking the manual and it doesn't explicitly say it's only when testing and not on compile... Which is possibly an oversight on my part!!! I'm almost 100% sure though that on compile the random functions are true random, and on debug it's a fixed seed....
I believe the starting seed is the same unless you specify randomize() in your code. 99% sure on that.
 

TheouAegis

Member
Not sure about YYC, but the normal compilers - both the green Play arrow and the Create Executable option - run the same seed every time. So you do need randomize(), no ifs, ands or butts.

And worse yet, the seed is static. It's not like it's based on the current time or anything.

if keyboard_check_pressed(vk_space) show_message(irandom(6));

Regardless of when you press the spacebar or where the object is in the room or anything that I can see at all, you'll get the same result every time.
 
A

Aura

Guest
The current random number generator maintains the same random seed every time you start the game. If you use the old random number generator with the help of random_use_old_version() then a new seed is generated every time IMO.
 

Yal

šŸ§ *penguin noises*
GMC Elder
When the game is compiled this will not be the case and the random functions should work as required.
This should be in the manual. People might build a game around the set seed always giving the same results and then not realize it isn't the same anymore when they release it.

(This is what the online version of the manual is saying on the matter)
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.
 
Top