I am having a very difficult time working with object variables. For instance:
How do I save a global object (nested variable/structure) to a scene object?
How do I save a scene variable node to a new variable? Example:
save quiz.questions to another variable questions
or
save questions[current_question_number] to question
It looks like the only way to store a global variable from a scene variable to is keep it a JSON string in global variables and parse it as JSON in the scene. Direct assignment like the first line below results in a zero value string or number.
Still, this method does not allow me to save a node of the global object to a new scene variable.
Hi and welcome here
Not sure what you call a node, but the change the scene variable action is the proper way to copy the content of a global variable to a scene variable.
But be careful, if your content is text, you need to use the appropriate action.
In this case, a node is a branch of a nested object. I have global variable âquizâ that is an object with a node called ârecordsâ representing questions.
So, Iâd like to assign quiz.records to a scene variable named âquestionsâ.
However, I canât even figure out how to assign the globalquiz variable directly to the scenequiz variable. This doesnât work.
OK. records is a child of the global variable âquizâ, itâs not a node or a branch of a nested object. quiz here is not an object. Please use our terminology on the forum, or weâll have a hard time understanding each other.
Youâre using the proper action if your content is numbers only.
Thanks for the help Gruk. However, Iâve been a software developer for 25 years and I can assure you that records is definitely a node. We are talking about the same thing. Letâs not get caught up in semantics.
How would you describe this global quiz variable if not an object? Global variable doesnât describe itâs type. I guess the engine uses the word structure.
My content is not numbers only. How would I assign a structure?
Well, we use node and branch for something else here, so please stick to child in this case. objects live on a scene, variables are variables.
[Deleted mistake]
Iâve been struggling with the same thing before bed last night. In my case needing to wipe a global variable with reset values in a load scene variable. Just for looking tidy so it wonât be line by line resetting each child. Anyway, see if this works for you. In action type json then pick Convert Json to scene variable. In the dialogue that pops up youâll see json string field, type J in it and of the 3 options that come up select GlobalVarToJSON(name) and in the âwhere to store itâ field type your scene variable. I just got done trying it in the debugger and itâs finally placing correct values for me. Give it a try and if thatâs not what youâre talking about, sorry.
@Lucky-j Thanks for the suggestion. Iâve done that as a workaround, as you can see in the original question code example. But, then I have to store each variable twice as a string and structure.
Also, Iâd like to assign a child of the variable to a scene variable. There is no way to isolate the child if parsing JSON.
hello, not sure if you still have the problem, but there is this extension called âextended variable supportâ it allows you to do sooo much stuff but in your case you can use the âobject variable to scene varableâ
youâre welcome