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

GameMaker Randomized grid game (help)

F

Fadi Nahhas

Guest
I'm trying to make a minigame that randomly places 25 symbols in a 5x5 grid
and it randomly chooses 4 of the symbols for the user to try to find in the grid within a certain amount of seconds.
 

TailBit

Member
let's say you got sprite spr_symbol with all 25 subimages as each symbol

- you can then make a ds_list
- use a loop to add the numbers 0-24 into it
- then do ds_list_shuffle
- you now read the first 4 of those into a separate list
- then do ds_list_shuffle again
- now .. the cards could be already laid out, then you could tell all of them:
Code:
with(obj_tile){
    image_index = other.list[| 0]; // set my image_index as the symbol of the top of the list
    ds_list_delete(other.list,0); // delete the symbol at the top of the list, so that the next tile gets the next
}
or create them as you read through em:
Code:
var i,a;
for(i=0;i<25;i++){
    a=instance_create(obj_tile, (i div 5) * 32, (i mod 5) * 32); // div and mod is very handy to go through all the grid positions with a single variable
    a.image_index = list[| i]; // then just pass over the symbol
}
- then delete the list

obj_tile would have image_speed set to 0 in the create event

Then you just have to check if the clicked image_index exists in the list of cards you should find..

Oh, you might need to do randomize() early in the game, or it will be using a default seed all the time and the shuffle results will be the same.

Hope that will help you get started[/CODE]
 
Last edited:
F

Fadi Nahhas

Guest
let's say you got sprite spr_symbol with all 25 subimages as each symbol

- you can then make a ds_list
- use a loop to add the numbers 0-24 into it
- then do ds_list_shuffle
- you now read the first 4 of those into a separate list
- then do ds_list_shuffle again
- now .. the cards could be already laid out, then you could tell all of them:
Code:
with(obj_tile){
    image_index = other.list[| 0]; // set my image_index as the symbol of the top of the list
    ds_list_delete(other.list,0); // delete the symbol at the top of the list, so that the next tile gets the next
}
or create them as you read through em:
Code:
var i,a;
for(i=0;i<25;i++){
    a=instance_create(obj_tile, (i div 5) * 32, (i mod 5) * 32); // div and mod is very handy to go through all the grid positions with a single variable
    a.image_index = list[| i]; // then just pass over the symbol
}
- then delete the list

obj_tile would have image_speed set to 0 in the create event

Then you just have to check if the clicked image_index exists in the list of cards you should find..

Oh, you might need to do randomize() early in the game, or it will be using a default seed all the time and the shuffle results will be the same.

Hope that will help you get started
Thank you so much, i didnt know about the ds list. makes it way easier.

im having a bit of trouble with the instance_create function, keep getting an error that variable is not set. is there a different command/function for it?
 

TailBit

Member
Sorry, instance_create_depth or instance_create_layer is what you must use .. I haven't made much instances since this version :p
 
F

Fadi Nahhas

Guest
Sorry, instance_create_depth or instance_create_layer is what you must use .. I haven't made much instances since this version :p
i did the instance_create_layer, it works but it spams the instances which causes the game to crash.
and it doesnt working if i put in inside the create event.


Edit: nvm got it to work. thank you so much
 
Last edited by a moderator:
Top