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

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello guys,

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

    Can someone help me please?

  • rollyzz .. first check this

    [quote:2qxn4yv0]I advise you to download this little program Array contents editor

    second

    pay attention on Array size and quotes...

    third

    "variable" in Array is just a simple string..

  • "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?

  • 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

  • "&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.

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

    so.. you have ArrayQuestions

    and you have Sprite "Image"

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

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

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

  • 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:

    "{""c2array"":true,""size"":[1,2,1],""data"":[[["VariableHere"],[0]]]}"[/code:1k40ca9u]
    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
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • After some few hours i find out a fix.

    You can add variables into that string like this (i will use my own example):

    "{""c2array"":true,""size"":[1,2,1],""data"":[[["&MyVariable&"],[0]]]}"[/code:2u52jenv]
    MyVariable (Global Text) = ""CAT""     - with double quotes
    
    So the string will become:
    
    [code:2u52jenv]"{""c2array"":true,""size"":[1,2,1],""data"":[[[""CAT""],[0]]]}"[/code:2u52jenv]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)