Target slot in global text variable

Get help using Construct 2

Post » Sat Mar 31, 2012 6:42 pm

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?
B
9
S
4
G
3
Posts: 223
Reputation: 3,433

Post » Sat Mar 31, 2012 8:27 pm

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.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Mon Apr 16, 2012 5:47 pm

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?
B
9
S
4
G
3
Posts: 223
Reputation: 3,433

Post » Mon Apr 16, 2012 6:56 pm

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
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755


Return to How do I....?

Who is online

Users browsing this forum: Matthew de, onzephyr and 0 guests