How do I call a global variable between layouts?

  • 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

    "Score: " & Score[/code:2zsxhuii] 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?
  • you used set value ?

    is it in a group? then it's a local value

    capx ?

  • 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)

  • full Editor: there you can upload

  • 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.

  • 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

  • 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'.

  • 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.

  • 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

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • volkiller730 Thanks for that debug tip. I'm using two text objects the only difference is that they have different font settings because it's required for the menu.

    @edwardr Ok I tried doing as you did and added an extra layout. For some reason, it does work now. I copied everything from the Restart layer to the new Restart layer and now it works! I have no clue what just happened, but it's working now. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)