How do I Set Text To Array Value

Get help using Construct 2

Post » Mon Jun 09, 2014 11:24 pm

Hello All & thanks for looking,

I can set text to Array.At(0) but how would I change that text to Array.At(1), Array.At(2), etc... with a key press or every X seconds?
B
25
S
7
Posts: 79
Reputation: 2,267

Post » Tue Jun 10, 2014 1:05 am

https://dl.dropboxusercontent.com/u/27336815/array.capx

I tried it, but Array is backwards. There could be even simpler solution but so far I haven't found any. Array lacks some events in my opinion.
B
6
S
2
Posts: 24
Reputation: 531

Post » Tue Jun 10, 2014 7:57 am

Couldn't this be solved with the array Push front action?
https://www.scirra.com/manual/108/array
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,370

Post » Tue Jun 10, 2014 11:28 pm

Thanks for the reply and the capx, Radiowaves. I really appreciate it. Your solution however has the same problem I was having, in that in order to change the text/value a different button would be needed to keep the values from escalating to their end point. I needed a one button solution so the player could just press B or A to continue the dialogue/text.
I solved it by removing the array all together and instead added an if tree and an instance to my text container that regulates the "escalating" effect.
I was hoping to find a more elegant solution - something like an Array.At(next) or Array.CurVal+1 but I couldn't figure it out.
As to the push front action - I couldn't get that to work for me either (I tried). What I think that does is add another value to the cell index instead of moving the values around (which would have worked for me). Having to add a value defeats the purpose of already having the array filled and ready to go. While I'm sure I could create a dialogue tree and populate the array with it in this way - it's less work just to plug in the tree "branches" when needed.

Thanks again, have a great day!
B
25
S
7
Posts: 79
Reputation: 2,267

Post » Wed Jun 11, 2014 9:48 am

You can use a variable to track the current index:
currentIndex = 0
set text to array.at(currentIndex )

when the player presses a button:
add 1 to currentIndex
set text to array.at(currentIndex )
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Fri Jun 20, 2014 4:26 am

ramones, thanks for the reply. This is (almost) exactly what I ended up doing. I used "set text" instead of an index array though.
B
25
S
7
Posts: 79
Reputation: 2,267

Post » Fri Jun 20, 2014 8:15 am

ramones wrote:You can use a variable to track the current index:
currentIndex = 0
set text to array.at(currentIndex )

when the player presses a button:
add 1 to currentIndex
set text to array.at(currentIndex )


An even more elegant solution involves adding a "currentindex" instance variable to the array object, in case your game logic involves keeping track of many conversations (stored in different array objects) at the same time. In that case, you use

Set Text to Array.At(Array.CurrentIndex)
Array Add to CurrentIndex 1

It's much more mantainable and in my opinion a better solution to your problem
B
6
S
2
Posts: 79
Reputation: 608


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, nahima and 16 guests