GameMaker variable_instance_set, but the variable is a ds_list

Bee

Member
I'm hoping there is a solution to this... I have a bunch of ds_lists that hold two values each. Then I have a json that refers to the ds_list names. So in order to adjust the values in the two list positions, how do I access them? I'm assuming I need to use variable_instance_set since the name references are strings.
 
H

Homunculus

Guest
You can do this in two ways:

1. Get the variable using variable_instance_get and use that as you normally would when dealing with a ds_list
2. Store the ds_lists in a ds_map and access them by using map[? list_name]

As a sidenote, do you know that you can save and load ds_lists directly using json?
 

Bee

Member
I can? Do tell!!!

I thought when you use variable_instance_get you're just getting the VALUE of the variable and not an actual reference to the variable. Am I wrong about that?
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I thought when you use variable_instance_get you're just getting the VALUE of the variable and not an actual reference to the variable. Am I wrong about that?
A "value" of a ds_list is a "reference" to a ds_list because it's just an index.
 
  • Like
Reactions: Yal
This help me today I hope to help someone else.

ISSUE:
variable_instance_get(instance_idX, "dsListOriginal")
when you use variable_instance_get to get a list from another instance what you get is not an instance of a list but a reference to it and it looks like i can't work with a reference the same as a real list. so...

SOLUTION:
var dsListCopy = ds_list_create();
ds_list_copy(dsListOriginalCopy,variable_instance_get(instance_idX, "dsListOriginal"));

now you can use dsListOriginalCopy for whatever you need.
remember to destroy the list when you don't need it anymore.
 

Yal

🐧 *penguin noises*
GMC Elder
This help me today I hope to help someone else.

ISSUE:
variable_instance_get(instance_idX, "dsListOriginal")
when you use variable_instance_get to get a list from another instance what you get is not an instance of a list but a reference to it and it looks like i can't work with a reference the same as a real list. so...

SOLUTION:
var dsListCopy = ds_list_create();
ds_list_copy(dsListOriginalCopy,variable_instance_get(instance_idX, "dsListOriginal"));

now you can use dsListOriginalCopy for whatever you need.
remember to destroy the list when you don't need it anymore.
What would you do if you need the original instance's list to be updated? Overwrite the reference with variable_instance_set? Because now you're actually working with a copy, not the original... important to not mix those things up.



Also, ListOriginalCopy as opposed to ListCopyCopy or ListAuxilaryCopy? :p
 
What would you do if you need the original instance's list to be updated? Overwrite the reference with variable_instance_set? Because now you're actually working with a copy, not the original... important to not mix those things up.



Also, ListOriginalCopy as opposed to ListCopyCopy or ListAuxilaryCopy? :p
Thank you, I hope this helps someone else.
 

Yal

🐧 *penguin noises*
GMC Elder
You didn't really answer my question, but I'll just interpret what you said as "yes" 🐧
 
Top