1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

New list at Runtime

Discussion in 'Programming' started by dcamod, Nov 8, 2019 at 4:25 PM.

  1. dcamod

    dcamod Member

    Joined:
    Feb 9, 2017
    Posts:
    58
    Hello all. I was just wondering how I should go about creating a button that when pressed creates a new unique list every time.
     
  2. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,846
    1. Place an object with a button sprite in the room
    2. In its Mouse Left Pressed Event,
    Code:
    randomize()
    mylist = ds_list_create()
    repeat(irandom(999)){
      ds_list_add(mylist,irandom(9999999))
    }
    //now you have a random list, do something with it
    
     
  3. dcamod

    dcamod Member

    Joined:
    Feb 9, 2017
    Posts:
    58
    Thanks for the reply but that is not exactly what I was looking for. I need a unique name for the list. This looks like it would just create a list named myList over and over with a random number assigned to index 0. I do not need the same list I need a unique list with a unique name.
     
  4. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,059
    Exactly what Yal said but add it to an array or list.
     
  5. dcamod

    dcamod Member

    Joined:
    Feb 9, 2017
    Posts:
    58
    Yeah great and all but what am I missing is what I was asking. No need to be rude. Never asked anyone to write my code for me, just trying to learn, you did not need to reply at all. That's awfully volatile and I reported you for it. If I am wrong please explain why instead of mocking me. How ridiculous and childish.

    I do see the random number is assigned as the array size now. So even mocking me you were helpful somewhat. I have not used arrays or lists for anything yet so I did not know. You could have just said that nicely. So the array has a unique index but not a unique name. I was looking for how to give it a unique name with a string. I did not mention I needed a string before, that is my fault.

    So, Samspade said add it to another list which I get, but how do I give it a string as it's name in the list.
     
    Last edited: Nov 12, 2019 at 6:20 PM
  6. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    49
    If you want to access data from that list by a string identifier it's going to be more complicated because internally there is no such thing. You will need a second reference map that you use to connect a label to a row in the ds list. Alternatively you could simply use a ds_map, it allows you to store a key => value pair and then you would use the ds_map_find_value() to search by the key (your label) and get the value you want.

    https://docs.yoyogames.com/source/dadiospice/002_reference/data structures/ds maps/index.html

    It should probably be worth noting that this is likely much slower than using an array, or ds_list, and referncing things by their ID rather than by string. If your going to be referencing many dozens of objects on every step by these labels you might want to rethink that, but if it's something your running once or every so often it should be fine. Even then, every step is probably okay, but only to some extent I imagine.
     

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