How do I call a global variable between layouts?

Get help using Construct 2

Post » Tue Feb 17, 2015 1:21 pm

I thought I would be able to call a global variable throughout different layouts but for some reason I'm not able to.

I have one layout 'Level1' and a layout 'Restart'. On Restart I am showing the final score.

I have a Text called 'Score' on Level 1. When the level is over, you go to layout 'Restart' where I want the Text Score2 to show the score of text 'Score'. I use the code
Code: Select all
"Score: " & Score
for both text objects. I have applied 'get Text' for every tick to both text objects. Global variable is named 'Score'.

I can't figure out why it's not working. Even copying text object 'Score' to the Restart layout doesn't work. It just says 'Score:' and doesn't show the actual score, not even the default.

I tried putting 'Score2' on layout Level 1 and now I it does call it. For some reason, it just won't set the Text of Score 2 to the score of 'Score' on other layouts.

What could I have done wrong?
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Tue Feb 17, 2015 1:29 pm

you used set value ?
is it in a group? then it's a local value

capx ?
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Tue Feb 17, 2015 3:34 pm

Hello,

I used set Text for the text objects. They're not in a group.

Ok so I still can't post any URL's yet for the .capx. I'd PM you or send it via Skype or something but even that requires 500 points and there are no other contact options on your profile. (Forum said I should choose that as alternative)
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Tue Feb 17, 2015 3:58 pm

full Editor: there you can upload
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Tue Feb 17, 2015 4:04 pm

Thanks for the tip. Can I remove the attachment later on though? Some forums don't allow this or the time expires for editing a comment.
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Tue Feb 17, 2015 4:06 pm

try this:
add global variable: test / number
on start of layout - set Value "test" 10

add text
every ticket - set text "test"

if you use several layers: do you load all event Sheets? (because each layer has own Event Sheets) Event sheet, right click, include Event sheet
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Tue Feb 17, 2015 4:42 pm

Hello,

I did as you told but not sure to which layout to add. It did work text was set to 10 on layout 'Level 1'.
Last edited by Rudi55 on Wed Feb 18, 2015 9:05 am, edited 1 time in total.
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Tue Feb 17, 2015 7:33 pm

ok you have the global variable in Events menu, where it is used and active, but not in Restart.

I would suggest that you put all global variables in an Extra Event sheet and then include it in all the others Event Sheets.
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Tue Feb 17, 2015 9:06 pm

@edwardr that is not how Global variables work you can access them no matter what if they are included or not.

@Rudi55 use the debug layout to make sure your global variable is being set right
also are you youing more then one textobject? you can just use one and use the same events for both

https://www.scirra.com/manual/83/variables
B
42
S
17
G
2
Posts: 850
Reputation: 6,209

Post » Tue Feb 17, 2015 10:28 pm

@volkiller730: you are right, i had once a similar problem, since that time I put them in a separate sheet.

@Rudi55: I checked and tried. My way doesn't change anything. I add also an separate variable (constant one) or change the text field. Nothing happened. It seems that all variable are lost. I'm sorry, but I didn't find a mistake.

The funny part: I add a new layout, just a blank one and changed if plane is destroyed go to the new layout and show variable. There it works. So the error is somewhere in the event restarts.
B
15
S
4
Posts: 77
Reputation: 1,030

Next

Return to How do I....?

Who is online

Users browsing this forum: kellehk, Voytek and 29 guests