• 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!

Legacy GM Choose random numbers and discard those that come out [Resolved]

wilmer

Member
Greetings to all:
I need help please with this code that I found, I want to use it to put it in a single room, and every time I go to that room, the code will show a random number and discard those that are already coming out. for example from 1 to 9, if it came out 5, it has to go from 1 to 9, any number except the 5. It's for a fight game where I'm going to put random matches, I see that the code is almost ready, but I want to know how to check the number that comes with a DRAW event and know in which event to put the second code.

This goes in the Create event
Code:
///Controller Object
globalvar numbers;
numbers = ds_list_create();
for(var i = 0; i <= 9; i++)
    ds_list_add(numbers, i); //The numbers from 0 to 9 are added
ds_list_shuffle(numbers);
This is the second code, I do not know in which event to put it.
does not specify me on the page where I found it

Code:
///When wanting to get a number
selected = numbers[| 0];
ds_list_delete(numbers, 0);
And I want to know how to show it with the DRAW event, those two things !!
 
In the Draw Event:
Code:
draw_text(x,y,string(selected));
That will draw the random number you have grabbed out of the list at the x and y position of the instance doing the drawing.

EDIT: Didn't see your first question, but yeah, @Taddio answered it below.
 
Last edited:
T

Taddio

Guest
Well...when do you want to get that number? Key press, mouse click, a collision between 2 objects, some range of time? The answer to that is probably the answer to your question too!
Edit: for question 2, see post above!!
 
Where you put the second code depends on your game.

For testing, you could put it in a Key Pressed Event. Then every time you press that key for example, [Space Key], a new number will be chosen.
 
Top