Target slot in global text variable

0 favourites
  • 4 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Really dumb question, how do i target specific slot in global text array

    ie ="|slot1|"slot2|slot3"

    i know how to get the data in the slot,

    int(tokenat(varname,slot,"|"))

    but how do i change the data of the specific slot

    say varname(3) = new number

    Also can you splice a segment?

    ie splice slot 2

    varname would = "|slot1|slot3"

    do i need to get each str and delete letters for each slot?

  • If you use this pattern: |index,value

    pets="|1,dog|2,cat|3,fish"

    To get the value at slot:

    tokenat(tokenat(pets, slot, "|"), 1, ",")

    To change the value of slot to newvalue:

    Set value pets to replace(pets, "|" & tokenat(pets, slot, "|"), "|" & slot & "," & newvalue)

    If you just add variables to the list then just append to the end increasing the index each time.

    eg. "|4,cow|5,rock"

    If you want to remove values from the list then instead of "|index,value" think of it as "|id,value".

    pets="|1,dog|2,cat|3,fish"

    Getting the value of a slot is the same:

    tokenat(tokenat(pets, slot, "|"), 1, ",")

    To change the value of slot to newvalue is a bit more complicated:

    Set value pets to replace(pets, "|" & tokenat(pets, slot, "|"), "|" & tokenat(tokenat(pets, slot, "|"), 0, ",") & "," & newvalue)

    Then you can also remove a slot like so:

    Set value pets to replace(pets, "|" & tokenat(pets, slot, "|"), "")

    You could also try using a plugin instead of dealing with just text as it would probably be simpler.

  • late late late late late reply but ive been working with this and trying to figure it out

    Ok none of this is working

    id try making it both ways textvar = "|slt|slt|slt|slt|slt"

    and = "|0,slt|1,slt|2,slt|3,slt|4,slt"

    when i try this Set value pets to replace(pets, "|" & tokenat(pets, slot, "|"), "|" & slot & "," & newvalue)

    in one way it will make everything in the array to the number im changing it to and not just the slot im trying to target

    so i will end up with "|2|2|2|2|2|" and not just the slot im targeting savvy?

    and with this one replace(pets, "|" & tokenat(pets, slot, "|"), "|" & tokenat(tokenat(pets, slot, "|"), 0, ",") & "," & newvalue)

    no matter what numbers i plug in it makes the whole array 0

    and can you please reitterate on the addding on the end?

    "|4,cow|5,rock"

    how exactly do you put it? to just add things on the end?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • With the fist way: "|slt|slt|slt|slt|slt"

    You can retrieve a certain slot but can't replace a certain slot because the slots are not unique.

    The second method is working for me, here is a capx:

    http://dl.dropbox.com/u/5426011/examples10/TextList.capx

    <img src="http://dl.dropbox.com/u/5426011/examples10/TextLIst.png" border="0">

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)