How do I save object variables

I am having a very difficult time working with object variables. For instance:

  1. How do I save a global object (nested variable/structure) to a scene object?

  2. 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.

Any ideas?

:wave: Hi and welcome here :slight_smile:
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.
image

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 global quiz variable directly to the scene quiz variable. This doesn’t work.

Ideally, I’d like to do what I described like this:

I believe I am using the proper actions.

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. :slight_smile:

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. :slight_smile:
objects live on a scene, variables are variables.
[Deleted mistake]

How’s this? I’d like to assign one global parent variable with many nested children of various types to a scene variable.

I’m using the same methods you suggested above. See the example code that does not work.

Can you please give me a code example?

[Deleted mistake]
Here’s how to proceed for structures:
image

That didn’t work. The resulting quiz variable is this:

Screen Shot 2023-01-23 at 12.03.03 PM

It converts my child to the string [structure].

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.

Just parse the child. Here I made a child that is also a structure with a number, a bool, and a string child in it. It looked ok in the debugger.

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

@Lucky-j Thanks for the code snippet. This look like it could be a workaround. I didn’t see the GlobalVarToJSON method.

@potato-coder That extension sounds juicy.

1 Like