1
\$\begingroup\$

I'm trying to make a game where the damage you deal is rolled by a dice. It all works. However, it keeps on giving the same values in a row so it isn't entirely random

ini_open("Health.ini");
attack = ini_read_real( "Attacks", "Felix", 0);
ini_close();
global.damage=0
repeat(attack){
global.damage=irandom(6)
}


if (global.damage ==0){instance_create_depth(300, 400, 0, obj_numbers0)}
if (global.damage ==1){instance_create_depth(400, 400, 0, obj_numbers1)}
if (global.damage ==2){instance_create_depth(500, 400, 0, obj_numbers2)}
if (global.damage ==3){instance_create_depth(600, 400, 0, obj_numbers3)}
if (global.damage ==4){instance_create_depth(700, 400, 0, obj_numbers4)}
if (global.damage ==5){instance_create_depth(800, 400, 0, obj_numbers5)}
if (global.damage ==6){instance_create_depth(900, 400, 0, obj_numbers6)}

The attack value is 1 because it is only one dice that is used for damage for now. The software I am using is Game Maker Studio 2

\$\endgroup\$
6
\$\begingroup\$

This is intended:

NOTE: This function will return the same value every time the game is run afresh due to the fact that GameMaker: Studio generates the same initial random seed every time to make debugging code a far easier task. To avoid this behaviour use randomize at the start of your game.

Check the reference here.

If you want to have it random every startup as well you'd have to call randomize(); once. Check that reference here.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.