How do i - Add a variable in JSON data to Load

Get help using Construct 2

Post » Wed Nov 04, 2015 11:05 am

Hello guys,

Wanted to add a variable into JSON data to load, and i get this:

Image

Can someone help me please?
B
7
S
1
Posts: 35
Reputation: 461

Post » Wed Nov 04, 2015 1:19 pm

@rollyzz .. first check this
I advise you to download this little program Array contents editor

second
Image
pay attention on Array size and quotes...

third
"variable" in Array is just a simple string..
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Wed Nov 04, 2015 1:37 pm

korbaach wrote: "variable" in Array is just a simple string..


Is there any way to add a variable in that string? I mean.. if i write ""variable"" the answer will be 'variable'.
I want to set that variable before loading.

Is that possible?
B
7
S
1
Posts: 35
Reputation: 461

Post » Wed Nov 04, 2015 1:42 pm

I guess that would have to be done the same way you add a variable in the middle of any other string..

"&variable&"

the first " closes the string
&variable adds the variable
&" is to open the string again
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Nov 04, 2015 1:48 pm

LittleStain wrote:"&variable&"


not working :(

This is the source: 1Pic_1Word.capx

All i want, is to change that "BEAR" into other variable, like in screanshoot.

variable = TEST;

so i should see just 4 black boxes. If i'll do like this : "&variable&", the code will go wrong, and will show me only 1 black box.
B
7
S
1
Posts: 35
Reputation: 461

Post » Wed Nov 04, 2015 2:22 pm

@rollyzz ..in example I set variable("CorrectAnswer"") fom Array...not the opposite

so.. you have ArrayQuestions

Image

and you have Sprite "Image"
Image

so..BEAR=0(frame)....CAMEL=1(frame)

if you want replace "BEAR" with "URS",just replace in Array "BEAR" with "URS" :)

Image

if you want replace "BEAR" let's say with "HORSE"
..just replace in Array "BEAR" with "HORSE"..and replace first frame...(Bear image with Horse image)..
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Wed Nov 04, 2015 9:05 pm

@korbaach Thank you sir!

I understand how this program works, but I need, if possible, to add that variable there.
Let me tell you in a detailed version why do I need this:
I have created a game with levels that shows you different pictures. You need to write in a textbox what you see in that pictures (the answers).
The answers are all variables like:
answer1 = cat;
answer2 = pool;
answer3 = dogs;
etc.

If you don't know the answer, you can click on a button that leads to a layout similar to "1Pic 1Word".
You see.. I need a way to add variables to that string.
I don't want to add them manually, because I have many levels, and all of them are using that layout. The only way this should work, is to add that variable in string.

So it will be like this:
Code: Select all
"{""c2array"":true,""size"":[1,2,1],""data"":[[["VariableHere"],[0]]]}"

where VariableHere is a global variable from previous layout. VariableHere = cat; for level1 and pool for level2, and dogs for level3.

Do you understand what am I trying to explain? Am I missing something? Let me know if I can explain you something else.

Thank you @korbaach, @LittleStain
B
7
S
1
Posts: 35
Reputation: 461

Post » Wed Nov 04, 2015 10:42 pm

After some few hours i find out a fix.
You can add variables into that string like this (i will use my own example):

Code: Select all
"{""c2array"":true,""size"":[1,2,1],""data"":[[["&MyVariable&"],[0]]]}"

MyVariable (Global Text) = ""CAT"" - with double quotes

So the string will become:

Code: Select all
"{""c2array"":true,""size"":[1,2,1],""data"":[[[""CAT""],[0]]]}"
B
7
S
1
Posts: 35
Reputation: 461


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests