still have questions about ds_list(I'm sorry that there are a lot of questions, I'm really a noob)

sinigrimi

Member
The first part is more or less solved, here is the second:

My rooms are randomly generated. I think that this can be written in ds_list as it is done here:
Code:
            map[? "chests"] = 1 + irandom(4);
            map[? "chest_list"] = ds_list_create();
            for (var a = 0; a < map[? "chests"]; a++;)
                {
                var _x = 96 + random(room_width - 160);
                var _y = 96 + random(room_height - 160);
                ds_list_add(map[? "chest_list"], _x, _y);
                }
            show_debug_message("CHESTS ADDED");
            }
but I have very, very many lines with creating objects. how can I effectively add them to ds_list. or maybe there are other options?

I have a script in which there is the following:

Code:
    if map[? "start"] == false
        {
        
                
        var Lvl1 =choose("BeeRoom")//, "RatRoom", "SpiderRoom");//,"RandomRoomOne","RandomRoomTwo","RandomRoomThree");
        map[? "enemy"] =Lvl1;
        show_debug_message(string_letters(Lvl1));
        map[?"fixed"] = Lvl1;
        map[?"fixed_list"] = ds_list_create();

in the controller the following:

Code:
var room_type = irandom_range(0,9);

case"fixed":
            // if (up == true) and (bottom == false) and (left ==false) and (right ==false){
         var _type = string_letters(map[? "fixed"]);
                 switch(_type){
                    case "BeeRoom":
                        fixed_BeeRoom(room_type);
                 }
             //}
             break;
    case "enemy":
        // if (up == true) and (bottom == false) and (left ==false) and (right ==false){         
   var _type = string_letters(map[? "enemy"]);
                switch(_type)
                    {
                    case "BeeRoom":
                         BeeRoom(room_type);
                        break;
in the scripts are switch systems in which everything is indicated in a similar way:
Code:
case 7:
spawn(1020,420,oStone);
spawn(900,540,oStone);
spawn(1140,540,oStone);
spawn(1020,660,oStone);
break;
I also attach a video in which you can see that the spawn of objects changes:

Addition: I do not aspire to do as indicated in the first spoiler, I need to spawn my objects at certain coordinates (in the fourth spoiler) but not be updated every time I return to the room

The first part is more or less solved, here is the second:
https://forum.yoyogames.com/index.p...questions-im-really-a-noob.71724/#post-423570
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Just fill out the DS map you use in the top example... But instead of storing the X/Y as part of the list, store it in the map. So, you'd have a DS map for each chest, each enemy, each item, etc... and each map would hold the thing to be created as well as its position and any other values it requires. Each map can then be added to the DS list and you can do what you want with it then. Just remember to call ds_map_destroy on all of them when you don't need them anymore!
 

sinigrimi

Member
Just fill out the DS map you use in the top example... But instead of storing the X/Y as part of the list, store it in the map. So, you'd have a DS map for each chest, each enemy, each item, etc... and each map would hold the thing to be created as well as its position and any other values it requires. Each map can then be added to the DS list and you can do what you want with it then. Just remember to call ds_map_destroy on all of them when you don't need them anymore!
oh damn it, I do not fully understand English and even such incomprehensible functions ... Could you give an example of how to do this? in the script I have to do "map [?"enemy "] = spawn (x, y, object)"? but then each next line will replace the previous one, so arrays are needed? It's hard to understand.
 

sinigrimi

Member
or
name = ds_map_create()
ds_map_add(name, obj1,x,y)

but even if it works, how can I indicate the correct number in a generation? because when I return to it Irandom_range works in it ... beeRoom (here you need the number). I read a bunch of articles, but didn’t understand anything. These features bore me.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, here's an example using chests and then enemies:

Code:
var _m = ds_map_create();
map[? "type"] = "Chests";
map[? "num"] = 5;
for (var i = 0; i < map[? "num"]; ++i;) // Add 5 chests to the map
{
map[? "x" + string(i)] = irandom(room_width);
map[? "y" + string(i)] = irandom(room_height);
}
ds_list_add(OBJECT_LIST, _m);

_m = ds_map_create();
map[? "type"] = "Enemies";
map[? "num"] = 5;
for (var i = 0; i < map[? "num"]; ++i;) // Add enemies to the map
{
map[? "enemy" + string(i)] = choose(obj_Enemy1, obj_Enemy2, obj_Enemy3);
map[? "x" + string(i)] = irandom(room_width);
map[? "y" + string(i)] = irandom(room_height);
map[? "hp" + string(i)] = 10 + irandom(10);
map[? "dmg" + string(i)] = 1 + random(1);
// add any other information required per enemy
}
ds_list_add(OBJECT_LIST, _m);

So, in the above example, we have two DS maps - one for chests and one for enemies - and we've added them to a DS list. Each DS map contains ALL the information for each of the objects that we want to spawn, including the number of each. For chests it's simply an X and a Y position, but for the enemies we store the enemy object that we want to spawn as well as the damage it does, it's hitpoints and its X and Y position. We could hold more too if required! And we don't need to use random for everything. For example, you could run a switch on the enemy object after it's been chosen and set fixed values for HP and DMG based on the object that was returned.

To then use these DS maps to create the objects we'd simply loop through the DS list to get each map back, then check the map "type", then use the information we know is in each map t create the required instances. In the end you'd have something like this:

Code:
for (var i = 0; i < ds_list_size(OBJECT_LIST); ++i;)
{
var _m = OBJECT_LIST[| i];
var _num = _m[? "num"];
switch (_m[? "type")
    {
    case "Chests":
        var _a = 0;
        repeat(_num)
            {
            var _inst = instance_create_layer(0, 0, "instances", obj_Chest);
            _inst.x = _m[? "x" + string(_a)];
            _inst.y = _m[? "y" + string(_a)];
            a++;
            }
        break;
    case "Enemies":
        var _a = 0;
        repeat(_num)
            {
            var _inst = instance_create_layer(0, 0, "instances", _m[? "enemy" + string(_a)]);
            _inst.x = _m[? "x" + string(_a)];
            _inst.y = _m[? "y" + string(_a)];
            _inst.hp = _m[? "hp" + string(_a)];
            _inst.dmg = _m[? "dmg" + string(_a)];
            _a++;
            }
        break;
    }
}

Finally, when you no longer need the list or the data in the list you need to clear the memory associated with it so you'd need to do:

Code:
for (var i = 0; i < ds_list_size(OBJECT_LIST); ++i;)
{
ds_map_destroy(OBJECT_LIST[| i]);
}
ds_list_destroy(OBJECT_LIST);
I hope that helps! I've used stuff like this a lot, especially in my Rogue-Like room and dungeon generators (click the link in my signature to see them!) and I know it can work really well. you just have to be organised and logical with the code.
 

sinigrimi

Member
Okay, here's an example using chests and then enemies:

Code:
var _m = ds_map_create();
map[? "type"] = "Chests";
map[? "num"] = 5;
for (var i = 0; i < map[? "num"]; ++i;) // Add 5 chests to the map
{
map[? "x" + string(i)] = irandom(room_width);
map[? "y" + string(i)] = irandom(room_height);
}
ds_list_add(OBJECT_LIST, _m);

_m = ds_map_create();
map[? "type"] = "Enemies";
map[? "num"] = 5;
for (var i = 0; i < map[? "num"]; ++i;) // Add enemies to the map
{
map[? "enemy" + string(i)] = choose(obj_Enemy1, obj_Enemy2, obj_Enemy3);
map[? "x" + string(i)] = irandom(room_width);
map[? "y" + string(i)] = irandom(room_height);
map[? "hp" + string(i)] = 10 + irandom(10);
map[? "dmg" + string(i)] = 1 + random(1);
// add any other information required per enemy
}
ds_list_add(OBJECT_LIST, _m);

So, in the above example, we have two DS maps - one for chests and one for enemies - and we've added them to a DS list. Each DS map contains ALL the information for each of the objects that we want to spawn, including the number of each. For chests it's simply an X and a Y position, but for the enemies we store the enemy object that we want to spawn as well as the damage it does, it's hitpoints and its X and Y position. We could hold more too if required! And we don't need to use random for everything. For example, you could run a switch on the enemy object after it's been chosen and set fixed values for HP and DMG based on the object that was returned.

To then use these DS maps to create the objects we'd simply loop through the DS list to get each map back, then check the map "type", then use the information we know is in each map t create the required instances. In the end you'd have something like this:

Code:
for (var i = 0; i < ds_list_size(OBJECT_LIST); ++i;)
{
var _m = OBJECT_LIST[| i];
var _num = _m[? "num"];
switch (_m[? "type")
    {
    case "Chests":
        var _a = 0;
        repeat(_num)
            {
            var _inst = instance_create_layer(0, 0, "instances", obj_Chest);
            _inst.x = _m[? "x" + string(_a)];
            _inst.y = _m[? "y" + string(_a)];
            a++;
            }
        break;
    case "Enemies":
        var _a = 0;
        repeat(_num)
            {
            var _inst = instance_create_layer(0, 0, "instances", _m[? "enemy" + string(_a)]);
            _inst.x = _m[? "x" + string(_a)];
            _inst.y = _m[? "y" + string(_a)];
            _inst.hp = _m[? "hp" + string(_a)];
            _inst.dmg = _m[? "dmg" + string(_a)];
            _a++;
            }
        break;
    }
}

Finally, when you no longer need the list or the data in the list you need to clear the memory associated with it so you'd need to do:

Code:
for (var i = 0; i < ds_list_size(OBJECT_LIST); ++i;)
{
ds_map_destroy(OBJECT_LIST[| i]);
}
ds_list_destroy(OBJECT_LIST);
I hope that helps! I've used stuff like this a lot, especially in my Rogue-Like room and dungeon generators (click the link in my signature to see them!) and I know it can work really well. you just have to be organised and logical with the code.
Thank you very much for your work, you were very kind to me. I’ll try to integrate it into my code tomorrow.
 

sinigrimi

Member
alas it does not work. I spent 2 hours but could not figure out what was the reason ...

monsters are not created, it does not reach the controller. in the end, I deleted this script to return what it was (I previously duplicated it in advance) but a window opened for me, I apparently stupidly clicked "Reload" and now I will restore from scratch what was previously. Amazing game maker

I need to somehow write down all these coordinates in the ds sheet and when I return to the room so that they are reproduced. I literally bang my head on the keyboard :D

Code:
        var Lvl1 = "BeeRoom";//choose("BeeRoom"...и так далее);
        map[? "enemy"] = Lvl1
     
     
     
     
        show_debug_message("1.Enemies ADDED");
        map[? "fixed"] = Lvl1
        map[? "fiixed_obj_list"] = ds_list_create();
     
     
        show_debug_message("2.Fixed objects ADDED");

Code:
    case"fixed":
            // if (up == true) and (bottom == false) and (left ==false) and (right ==false){
         var _type = string_letters(map[? "fixed"]);
                 switch(_type){
                    case "BeeRoom":
                        fixed_BeeRoom(room_type);
                 }
             //}
             break;

it is from this script that I need the coordinates to be recorded in ds_list, random ones do not fit(below):

Code:
#region общий
switch(argument0){
#region  case #0
    case 0: //#1 bee
        instance_create_layer(180,300,"Instances",oStone);
        instance_create_layer(300,300,"Instances",oStone);
        instance_create_layer(420,300,"Instances",oStone);
        instance_create_layer(780,300,"Instances",oStone);
        instance_create_layer(1140,300,"Instances",oStone);
        instance_create_layer(1500,300,"Instances",oStone);
        instance_create_layer(1620,300,"Instances",oStone);
        instance_create_layer(1740,300,"Instances",oStone);
        instance_create_layer(540,420,"Instances",oStone);
        instance_create_layer(660,420,"Instances",oStone);
        instance_create_layer(1260,420,"Instances",oStone);
        instance_create_layer(1380,300,"Instances",oStone);
        instance_create_layer(540,660,"Instances",oStone);
        instance_create_layer(660,660,"Instances",oStone);
        instance_create_layer(1260,660,"Instances",oStone);
        instance_create_layer(1380,660,"Instances",oStone);
        instance_create_layer(180,780,"Instances",oStone);
        instance_create_layer(300,780,"Instances",oStone);
        instance_create_layer(420,780,"Instances",oStone);
        instance_create_layer(780,780,"Instances",oStone);
        instance_create_layer(1140,780,"Instances",oStone);
        instance_create_layer(1500,780,"Instances",oStone);
        instance_create_layer(1620,780,"Instances",oStone);
        instance_create_layer(1740,780,"Instances",oStone);
break;
#endregion
#region case #1
case 1:
spawn(780,300,oSpikes);
spawn(1140,300,oSpikes);
spawn(660,420,oSpikes);
spawn(1260,420,oSpikes);
spawn(780,780,oSpikes);
spawn(1140,780,oSpikes);
spawn(660,660,oSpikes);
spawn(1260,660,oSpikes);
break;

#endregion
#region case #2
case 2:
spawn(420,300,oStone);
spawn(900,300,oStone);
spawn(1020,300,oStone);
spawn(1500,300,oStone);
spawn(550,420,oSpikes);
spawn(1260,420,oSpikes);
spawn(300,540,oSpikes);
spawn(1620,540,oSpikes);
spawn(660,660,oSpikes);
spawn(1260,660,oSpikes);
break;
#endregion
#region case #3
case 3:
spawn(540,300,oAbyss);
spawn(660,300,oAbyss);
spawn(1260,300,oAbyss);
spawn(1380,300,oAbyss);
spawn(300,420,oAbyss);
spawn(1620,420,oAbyss);
spawn(300,540,oAbyss);
spawn(660,540,oAbyss);
spawn(780,540,oAbyss);
spawn(1140,540,oAbyss);
spawn(1260,540,oAbyss);
spawn(1620,540,oAbyss);
spawn(300,660,oAbyss);
spawn(1620,660,oAbyss);
spawn(540,780,oAbyss);
spawn(660,780,oAbyss);
spawn(1260,780,oAbyss);
spawn(1380,780,oAbyss);
break;
#endregion
#region case #4
case 4:
spawn(300,300,oAbyss);
spawn(420,300,oAbyss);
spawn(540,300,oAbyss);
spawn(660,300,oAbyss);
spawn(780,300,oAbyss);
spawn(900,300,oAbyss);
spawn(1020,300,oAbyss);
spawn(1140,300,oAbyss);
spawn(1380,300,oAbyss);
spawn(1500,300,oAbyss);
spawn(1620,300,oAbyss);
spawn(1020,420,oAbyss);
spawn(300,540,oAbyss);
spawn(420,540,oAbyss);
spawn(540,540,oAbyss);
spawn(660,540,oAbyss);
spawn(780,540,oAbyss);
spawn(1020,540,oAbyss);
spawn(1140,540,oAbyss);
spawn(1260,540,oAbyss);
spawn(1380,540,oAbyss);
spawn(1500,540,oAbyss);
spawn(1620,540,oAbyss);
spawn(1020,660,oAbyss);
spawn(180,780,oAbyss);
spawn(300,780,oAbyss);
spawn(420,780,oAbyss);
spawn(540,780,oAbyss);
spawn(780,780,oAbyss);
spawn(900,780,oAbyss);
spawn(1020,780,oAbyss);
spawn(1140,780,oAbyss);
spawn(1380,780,oAbyss);
spawn(1500,780,oAbyss);
spawn(1620,7280,oAbyss);
break;

#endregion
#region case #5
case 5:
spawn(780,300,oSpikes);
spawn(1140,300,oSpikes);
spawn(540,420,oSpikes);
spawn(1380,420,oSpikes);
spawn(780,540,oSpikes);
spawn(1140,540,oSpikes);
spawn(540,660,oSpikes);
spawn(1380,660,oSpikes);
spawn(780,780,oSpikes);
spawn(1140,780,oSpikes);
break;
#endregion
#region case #6
case 6:
spawn(660,300,oSpikes);
spawn(1280,300,oSpikes);
spawn(420,540,oSpikes);
spawn(780,540,oSpikes);
spawn(1140,540,oSpikes);
spawn(1500,540,oSpikes);
spawn(660,780,oSpikes);
spawn(1260,780,oSpikes);
break;
#endregion
#region case #7
case 7:
spawn(1020,420,oStone);
spawn(900,540,oStone);
spawn(1140,540,oStone);
spawn(1020,660,oStone);
break;
#endregion
#region case #8
case 8:
spawn(560,300,oSpikes);
spawn(1260,300,oSpikes);
spawn(780,420,oSpikes);
spawn(900,420,oSpikes);
spawn(1020,420,oSpikes);
spawn(1140,420,oSpikes);
spawn(420,540,oSpikes);
spawn(780,540,oSpikes);
spawn(1140,540,oSpikes);
spawn(1500,540,oSpikes);
spawn(780,660,oSpikes);
spawn(900,660,oSpikes);
spawn(1020,660,oSpikes);
spawn(1140,660,oSpikes);
spawn(660,780,oSpikes);
spawn(1260,780,oSpikes);
break;

#endregion
#region case #9
case 9:
spawn(300,300,oStone);
spawn(540,300,oStone);
spawn(780,300,oStone);
spawn(1020,300,oStone);
spawn(1260,300,oStone);
spawn(1500,300,oStone);
spawn(1740,300,oStone);
spawn(180,540,oStone);
spawn(420,540,oStone);
spawn(660,540,oStone);
spawn(900,540,oStone);
spawn(1140,540,oStone);
spawn(1380,540,oStone);
spawn(1620,540,oStone);
spawn(300,780,oStone);
spawn(540,780,oStone);
spawn(780,780,oStone);
spawn(1020,780,oStone);
spawn(1260,780,oStone);
spawn(1500,780,oStone);
spawn(1740,780,oStone);
break;
#endregion
}
#endregion
 
Last edited by a moderator:

sinigrimi

Member
upd: I solved the problem of generating a random number by making such a move (yes, I’m stupid and couldn’t understand how to use it for two days, LOL)

Code:
        map[?"typeRoom"] = ds_list_create()
         var type_room = irandom(9);
         ds_list_add(map[?"typeRoom"],type_room)


Code:
    case"fixed":
            // if (up == true) and (bottom == false) and (left ==false) and (right ==false){
           
            var room_type = ds_list_find_value(map[? "typeRoom"],0)
         var _type = string_letters(map[? "fixed"]);
                 switch(_type){
                    case "BeeRoom":
                        fixed_BeeRoom(room_type);
                 }
             //}
             break;


but I still have a question what to do with this? I want that if I destroy some objects they will not be reborn after I return to the room. Do I need to add each object to ds_list and in the conditions of destruction register ds_list_remove? What is the best way and can it be done in bulk (so as not to introduce each)

Code:
#region общий
switch(argument0){
#region  case #0
    case 0: //#1 bee
        instance_create_layer(180,300,"Instances",oStone);
        instance_create_layer(300,300,"Instances",oStone);
        instance_create_layer(420,300,"Instances",oStone);
        instance_create_layer(780,300,"Instances",oStone);
        instance_create_layer(1140,300,"Instances",oStone);
        instance_create_layer(1500,300,"Instances",oStone);
        instance_create_layer(1620,300,"Instances",oStone);
        instance_create_layer(1740,300,"Instances",oStone);
        instance_create_layer(540,420,"Instances",oStone);
        instance_create_layer(660,420,"Instances",oStone);
        instance_create_layer(1260,420,"Instances",oStone);
        instance_create_layer(1380,300,"Instances",oStone);
        instance_create_layer(540,660,"Instances",oStone);
        instance_create_layer(660,660,"Instances",oStone);
        instance_create_layer(1260,660,"Instances",oStone);
        instance_create_layer(1380,660,"Instances",oStone);
        instance_create_layer(180,780,"Instances",oStone);
        instance_create_layer(300,780,"Instances",oStone);
        instance_create_layer(420,780,"Instances",oStone);
        instance_create_layer(780,780,"Instances",oStone);
        instance_create_layer(1140,780,"Instances",oStone);
        instance_create_layer(1500,780,"Instances",oStone);
        instance_create_layer(1620,780,"Instances",oStone);
        instance_create_layer(1740,780,"Instances",oStone);
break;
#endregion
#region case #1
case 1:
spawn(780,300,oSpikes);
spawn(1140,300,oSpikes);
spawn(660,420,oSpikes);
spawn(1260,420,oSpikes);
spawn(780,780,oSpikes);
spawn(1140,780,oSpikes);
spawn(660,660,oSpikes);
spawn(1260,660,oSpikes);
break;

#endregion
 
Top