Appending string according to player position

Get help using Construct 2

Post » Thu Aug 08, 2013 12:27 pm

I have a player object moving upwards. On the level layout there are letter objects scattered around, ie.: AABBCD. Each is placed higher then the other. So A is at the bottom and the D is in the top.

Every tick I want to check what 4 letters will be the next letters that player can collect - what 4 next letters are now higher then the player object. These 4 letters I want to print. I implemented it already, but somehow it's not working for last 3 letters or less. It should work like this: if less then 4 letters are ahead of the player, display just 3 letters, etc. In my implementation if there is just one letter ahead (ie.: E) it creates string: EEEE, and not: E.

I don't know how to make it work. Here is my .capx: http://www.sendspace.com/file/4y3wcj

Thanks!

B
2
Posts: 2
Reputation: 154

Post » Thu Aug 08, 2013 6:20 pm

Here try this:

next4Treasures.capx
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Thu Aug 08, 2013 7:53 pm

Thanks @ramones :) It's working great. I'm just wondering why there should be the first line? Why are you setting Text to "" everytime one of the treasures gets behind the player?
B
2
Posts: 2
Reputation: 154

Post » Thu Aug 08, 2013 10:11 pm

I just set the text to blank and then append the 4 letters in the loop. If you didn't set the text to "" first you'd be continuously adding letters onto the end of the string.

You could add the the letters to a variable and then set the text equal to that variable if you wanted to do it that way.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests