For loop not completely working?

Discussion and feedback on Construct 2

Post » Mon Mar 31, 2014 8:17 am

Hi guys, I've got the following event sheet:

Image

However, only the first two text fields get set, but the buttons do show and when clicked do what they should do. The following JSON code is behind LIST:

Code: Select all
{"c2array":true,"size":[4,3,1],"data":[[["2kt2JbodBptBZCuPxKDKGQ"],["3434"],[1]],[["Mx+ENw3RXZfdfDCyM6P8kQ"],["Tariq is xx"],[1]],[["RC9SJZNPUYNon8nUi-6BRA"],["Of nee, Tariq is xx'],[1]],[["bdmbGBb5xxKeOJzjhFyuiA"],["Verhaal12345"],[1]]]}


Does anybody see what the problem is?
Last edited by QuincyDK on Tue Apr 01, 2014 8:07 am, edited 1 time in total.
B
7
S
2
G
2
Posts: 46
Reputation: 769

Post » Mon Mar 31, 2014 2:47 pm

I wasn't going to log on, but your did 4 horrible things here.

1. Don't clone or duplicate objects as your doing.
Instead create 1 Object, give them a custom variable name/id.
Sprite1,2,3,4,5 is bad
Text 1,2,3,4,5 is bad
instead
Sprite.id = 1, Sprite.id = 2, Sprite.id = 3, Sprite.id = 4, Sprite.id = 5
same with text you have


2. You don't list all valid numbers.
You use curStory to check against for the IF statements, yet we don't know where curStorys starts.
AND
Button Loop starts at 1, but we have no idea what numberStory last number.

3. If your not using the LoopIndex("Button") to get your number
Do you really need a loop?

4. If Number story which set's the loop count is related to your Array. Your Array Width is only 4. If your loop is based on Array Width then the loop only last's to a count of 4. If your loop count is for then CurStory will only ever be starting value of curStory + 4.

5. Did I say 4? I meant 5.
We are here to help, however the website is supposed to family friendly. And while I know the word "gay" can be jolly, such as "a gay old time" to mean a happy jolly time. The current slang and the context of use can be derogatory.



Instead you should destroy what you have and make it over all better.
Assign the variables to the objects instead of duplicating objects. This means you only need to include it in the list once.


For Loop Button 4 to 8
--//Event to build SOL would be
--Text.id = loopindex("Button")
--Sprite.id=loopindex("Button")
--// actions would be
Sprite.visible set true
Text.visible set true
Text..text = titlevalue
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,038

Post » Mon Mar 31, 2014 3:09 pm

What is the starting value for curStory? and starting value for storyTitle? and value of numberStory?

if curStory starts at 1, and numberStory is 5, then the first 2 times through the loop nothing will happen because curStory would be 2, then 3 - and you don't start setting the text fields until it gets to 4.

Also, it looks like you are trying to set up a menu of 5 titles, but your json array only has data for 4. And since the loop may not be doing anything the first two times it runs, then after that it may be setting text fields on the 3rd and 4th times through - and then running out of data in the array...

but I would need to see a little more code to know for sure...

(well, I see jayderyu beat me to it, lol) :)
B
98
S
35
G
20
Posts: 438
Reputation: 17,875

Post » Tue Apr 01, 2014 8:09 am

jayderyu wrote:I wasn't going to log on, but your did 4 horrible things here.

1. Don't clone or duplicate objects as your doing.
Instead create 1 Object, give them a custom variable name/id.
Sprite1,2,3,4,5 is bad
Text 1,2,3,4,5 is bad
instead
Sprite.id = 1, Sprite.id = 2, Sprite.id = 3, Sprite.id = 4, Sprite.id = 5
same with text you have


2. You don't list all valid numbers.
You use curStory to check against for the IF statements, yet we don't know where curStorys starts.
AND
Button Loop starts at 1, but we have no idea what numberStory last number.

3. If your not using the LoopIndex("Button") to get your number
Do you really need a loop?

4. If Number story which set's the loop count is related to your Array. Your Array Width is only 4. If your loop is based on Array Width then the loop only last's to a count of 4. If your loop count is for then CurStory will only ever be starting value of curStory + 4.

5. Did I say 4? I meant 5.
We are here to help, however the website is supposed to family friendly. And while I know the word "gay" can be jolly, such as "a gay old time" to mean a happy jolly time. The current slang and the context of use can be derogatory.



Instead you should destroy what you have and make it over all better.
Assign the variables to the objects instead of duplicating objects. This means you only need to include it in the list once.


For Loop Button 4 to 8
--//Event to build SOL would be
--Text.id = loopindex("Button")
--Sprite.id=loopindex("Button")
--// actions would be
Sprite.visible set true
Text.visible set true
Text..text = titlevalue


Woops, I did not even realize that I went overboard with the JSON, I edited that out.

Thanks alot, this has pushed me into the right direction :) I'll be more careful next time with supplied data and make sure to include more (detailed) info :p
B
7
S
2
G
2
Posts: 46
Reputation: 769


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 11 guests