RESOLVED ..! how can we ensure that a random number is not selected again

Discussion in 'Programming' started by eneskaplan34, Oct 10, 2019.

  1. eneskaplan34

    eneskaplan34 Member

    Joined:
    Oct 2, 2019
    Posts:
    3
    Create;

    global.roomno = irandom_range(1,4);
    global.rm_go = asset_get_index("q_room"+string(global.roomno));

    Mouse Clicking;
    room_goto(global.rm_go);
    ..
    I'm organizing random rooms for quiz and I'd appreciate it if you help.
     
  2. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,742
    Add all the unique numbers you want to use to a ds_list, shuffle it with ds_list_shuffle, remove values one at a time until the list is empty.
     
    eneskaplan34 likes this.
  3. Liam Jacobs

    Liam Jacobs Member

    Joined:
    Jul 1, 2016
    Posts:
    159

    Yal's idea was good, but there's another way to do this that'd be a bit easier:

    1. Add all of the rooms to a DS list.
    2. Use ds_list_shuffle to randomize the rooms.
    3. Remove the room from the DS list, and then go to it.

    Or alternatively, just use one room, and draw the quiz question + options dynamically.
     
    eneskaplan34 likes this.
  4. Roderick

    Roderick Member

    Joined:
    Jun 22, 2016
    Posts:
    580
    When the program starts, set global.roomno and global.rm_go to the value of the first room, if you aren't already doing that.
    Code:
    #Create
    # roomno is now the current room,
    # rm_go is the target room
    while (global.roomno == global.rm_go)
    {
      global.rm_go = irandom_range(1, 4);
    }
    
    #Mouse click
    room_goto(asset_get_index("q_room"+string(global.rm_go)));
    
     
    eneskaplan34 likes this.
  5. eneskaplan34

    eneskaplan34 Member

    Joined:
    Oct 2, 2019
    Posts:
    3
    Test için rastgele odalar düzenliyorum ve yardımcı olursanız sevinirim.
    I'm new to game maker I made a list, but then I do not know how to go to the room and do not know how to get up to the code above
    Code:
    create;
    rooms = ds_list_create();
    
    ds_list_add(rooms, q_room1);
    ds_list_add(rooms, q_room2);
    ds_list_add(rooms, q_room3);
    ds_list_add(rooms, q_room4);
    
    ds_list_shuffle(rooms);
    
    What will I do next?
     
    Liam Jacobs likes this.
  6. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,908
    When the time comes to go to the next room:

    room_goto(rooms[|0]);
    ds_list_delete(rooms,0);
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice