GameMaker Сhoose doesn't work randomly [SOLVED]

sinigrimi

Member
I use function "choose()" and "randomize()" but they don't work.
I’m constantly creating the event "Random_room2"



The following is written in my script:
Script-Code:

Code:
randomize();
        var Lvl1 = choose("Bee_room", "Rat_room", "Spider_room","Random_room1","Random_room2","Random_room3");
        map[? "enemy"] = Lvl1;
        show_debug_message("ENEMIES ADDED");


And in my controller (create event) the following is written:
Controller-Code:

Code:
case "enemy":
    
   var _type = string_letters(map[? "enemy"]);
            var _xx = 160 + random(room_width - 320);
            var _yy = 160 + random(room_height - 320);
                switch(_type)
                    {
                    case "Bee_room":
                         instance_create_layer(_xx, _yy, "Instances", oBee)
                        break;
                    case "Rat_room":
                         instance_create_layer(_xx, _yy, "Instances", oRat)
                        break;
                    case "Spider_room":
                         instance_create_layer(_xx, _yy, "Instances", oSpider)
                        break;
                     case "Random_room1":
                         instance_create_layer(_xx, _yy, "Instances", oChervyak)
                        break;                   
                     case "Random_room2":
                         instance_create_layer(_xx, _yy, "Instances", oEvilEye)
                        break;
                    case "Random_room3":
                         instance_create_layer(_xx, _yy, "Instances", oPlayer)
                        break;
}
        break;
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Your Switch is formatted wrongly? You have cases outside of the {} in the code you posted above... If that's not the complete code then you need to show it, as you also don't show where you call the script.
 

sinigrimi

Member
Upd: I found my mistake, it was that the code reads only letters, while my events in the title had numbers and signs like "_". I changed it and it worked. Nocturne, thanks for finding an error with "{}" this also ruined my head :)


Your Switch is formatted wrongly? You have cases outside of the {} in the code you posted above... If that's not the complete code then you need to show it, as you also don't show where you call the script.
I put "}" (also corrected in a post), but it made it worse, now monsters do not appear at all. I am trying to do this in your code "Rogue-like Room Generator"


end in debug message have report:
Room 1 is a map!
TRAPS ADDED
Spiderroom
Room 2 is a map!
Ratroom
Room 3 is a map!
Spiderroom
Room 4 is a map!
-------TREASURE ADDED
TRAPS ADDED
Spiderroom
Room 5 is a map!
Randomroom
Room 6 is a map!
TRAPS ADDED
Spiderroom
CHESTS ADDED
Room 7 is a map!
Randomroom
Room 8 is a map!
Randomroom
 
Last edited:

gnysek

Member
Can you just use [code ] [/ code] tags ? I can see nothing in your post:

upload_2020-1-29_12-47-48.png

Also, var _type = string_letters(map[? "enemy"]); will give you string containing only letters, so "_" will be removed. So, the cases in switch should be for example Beeroom not Bee_room.

Choose works OK, it's string_letters which you understand wrong. Using show_debug_message to check what _type contains just before switch() would tell you all your problems.

Edit: ouuups, I forgot to submit my post and you already found the answer in meantime :)
 
Top