Statement execution order - can somebody explain?

hardkrafthardkraft Member Posts: 28
edited October 2014 in Working with GS (Mac)

Hi,
I created a simple test project which gives very unexpected results.
I have a game variable var1. Inside an actor I initialize it to 1, then display it’s value on the screen, then I have a rule if var1=1 and have a debug statement inside that rule as well as text display of var1.
At the end of the actor code I reset var1 to 0
https://dropbox.com/s/jfrqd2wjnvm8lni/Screen%20Shot.JPG

What happens:

  • first display shows 0 even though I initialized var1 to 1 just prior
  • displays inside the rule don’t execute, which would make sense if it thinks that var1 is 0 however log statements Do execute and show var1=1

Can anyone explain what’s going on?
Attached is the copy of the project:
https://dropbox.com/s/xseaoiuccapf3xz/test1.gameproj.zip?dl=0

«1

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited October 2014

    @hardkraft said:
    I have a game variable var1. Inside an actor I initialize it to 1 . . .

    You might be better off sticking to GameSalad terms to avoid confusion, I take it a variable is an attribute and you are using 'initialize' to mean change a value with the change attribute behaviour, or maybe by 'initialise' you mean you change the default value of the attribute ?

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Are you asking why you don't actually see the text updating on screen? If so it's because it all happens so quickly (in milliseconds) so the zero is the only thing that ever gets drawn to the screen.

    If you add a Timer Behavior around your three bottom rules so it looks like:

    Timer After 1 second (run to completion)
    
    Rule
    
    Change Attribute
    
    Log Debugging Statement
    

    You can see the numbers update on screen...

  • hardkrafthardkraft Member Posts: 28

    @Socks said:
    variable is an attribute and you are using 'initialize' to mean change a value with the change attribute behaviour, or maybe by 'initialise' you mean you change the default value of the attribute ?

    Thanks, that’s correct.

  • hardkrafthardkraft Member Posts: 28

    @jamie_c said:
    it's because it all happens so quickly (in milliseconds) so the zero is the only thing that ever gets drawn to the screen.

    Thanks, but that doesn’t explain why if I remove the initial text output none of the text from the inside the rule gets outputted to the screen. The box just stays blank.

  • BBEnkBBEnk Member Posts: 1,764

    You have a change attribute at the bottom of your rules thats changes it back to 0. rules run top to bottom, layers run bottom to top.

  • hardkrafthardkraft Member Posts: 28

    I tried the timer and it did work, sort of. It displayed the value of 0 which I assume is because I reset it back to 0 after the rule. The question still is why nothing gets displayed without the timer.

  • BBEnkBBEnk Member Posts: 1,764

    because its too fast without a timer.

  • hardkrafthardkraft Member Posts: 28

    @BBEnk said:
    rules run top to bottom, layers run bottom to top.

    I’d expect them to run top to bottom. I imagine they should go like this:

    • attr set to 1
    • text displays 1
    • rule var1=1 gets triggered
    • log displays 1
    • text inside the rule displays 1
    • attr set to 0

    It doesn’t seem to be happening in that order. Do you know the order that it’s actually happening and why?

  • hardkrafthardkraft Member Posts: 28

    @BBEnk said:
    because its too fast without a timer.

    Sorry, I don’t follow. Too fast to display anything? The rule gets entered, the log says so, but the text next to the log does not display.

  • SocksSocks London, UK.Member Posts: 12,822

    . . . are using 'initialize' to mean change a value with the change attribute behaviour, or maybe by 'initialize' you mean you change the default value of the attribute ?

    @hardkraft said:
    Thanks, that’s correct.

    Ah, the old 'answer-'Yes'-to-a-choice-question' method, lol :smile:

  • hardkrafthardkraft Member Posts: 28
    edited October 2014

    @Socks said:
    . . . are using 'initialize' to mean change a value with the change attribute behaviour, or maybe by 'initialize' you mean you change the default value of the attribute ?

    In this case I believe it’s both. I change the attribute which changes the default value that was in it.

    I provided the screen shot if you have any questions.

  • BBEnkBBEnk Member Posts: 1,764

    GameSalad runs very fast and the change from 1 to 0 is to fast for you to see but it does happen your using the same attribute to display the same thing so you only see a 0.

    heres a trimmed down version of your code does same thing.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Honestly I think the changes occur so quickly when the program runs, you just don't 'see' it.

  • hardkrafthardkraft Member Posts: 28
    edited October 2014

    @BBEnk said:

    heres a trimmed down version of your code does same thing.

    But you trimmed away the most important part, the rule. It’s the rule that’s causing the issues. Things execute ok outside the rule but not inside of it.

  • SocksSocks London, UK.Member Posts: 12,822

    @hardkraft said:
    In this case I believe it’s both. I change the attribute which changes the default value that was in it.

    One is achieved without a behaviour by simply changing the default value, one is done using a behaviour, the point was really one about avoiding using non-GameSalad terms as they might introduce some confusion, it was just a suggestion, you can use whatever language you like of course.

  • hardkrafthardkraft Member Posts: 28
    edited October 2014

    @jamie_c said:
    Honestly I think the changes occur so quickly when the program runs, you just don't 'see' it.

    Maybe the confusion stems from the first display behavior. Did you have a chance to look at the code I posted? If you turn off the first display the code should enter the rule and display something. Why doesn’t it display anything at all even though it does enter it?

  • BBEnkBBEnk Member Posts: 1,764

    your rule did nothing thats my point the result was still attribute changed from 0 to 1 back to 0 here your test a little different with timers you can watch what happens.

  • hardkrafthardkraft Member Posts: 28
    edited October 2014

    @BBEnk said:
    your rule did nothing thats my point the result was still attribute changed from 0 to 1 back to 0 here your test a little different with timers you can watch what happens.

    The example I provided is simple but the point is to see what happens inside the rule and in which order it gets executed, the use of the rule is the whole point. As of now it looks the rule gets executed AFTER the reset of the attribute even though it comes BEFORE it (but not really since the log statements do get executed in the proper order).

    Can you see a few posts up I listed the order that I think it should execute in. Are my assumptions wrong, could you list what you think gets executed and in what order?

  • hardkrafthardkraft Member Posts: 28

    I did another test. I switched off the attr change at the bottom. So basically var1 gets 1 at the top and that’s it. Now the rule enters correctly. Why would attr change have an effect on the rule that comes before it?

  • BBEnkBBEnk Member Posts: 1,764

    because rules in actors run from top to bottom, and the layers read from bottom to top and I get what your asking now see new test. the top has a timer so you can see it happen the bottom has no timer and will happen instant.

    top uses var1

    bottom I made a var 2

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited October 2014

    Here is what I see in your source file:

    Change Attribute: you update the value of var1 to 1
    
    Display Text: you display the value of var1 (which never shows on screen)
    
    Rule: If var1 = 1 (which it will)
    
         Log Debug of var1 which logs 1
    
         Display Text: you display the value of var1 (which never shows on screen)
    
         Rule: If var1 = 1 (which it will) This rule is placed inside the rule above
    
              Display Text: you display the value of var1 (which never shows on screen)
    
              Log Debug of var1 which logs 1
    
              Otherwise:
    
                    Display Text (will never happen because var1 =1)
    
                    Log Debug of var1 (will never happen because var1 =1)
    
    Change Attribute: var1 = 0
    
    Log Debug of var1 which logs 0
    

    And my debug log says

    1
    1
    0
    

    Which is exactly what I'd expect. You just never see the display texts being 1 because it all happens so quickly... it only ever shows 0.

  • hardkrafthardkraft Member Posts: 28

    @jamie_c‌
    Great, looks like we are on the same page. Could you tell me why you wouldn’t expect any of the displays to display anything?

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited October 2014

    Besides the fact that it happens to fast to display, no. :) Honestly, it's just happening so fast you can't see it... by the time you change var1 to 0, that is all you see displayed.

    Adding Timers to slow it down, like BBEnk and I have done already, allow the text to display.

  • hardkrafthardkraft Member Posts: 28

    @jamie_c I thought that once something is displayed it stays on the screen, it doesn’t display and then disappear. If you remove the very top display the screen will remain blank.

    Besides, when I remove the bottom attr change everything displays as expected, why?

  • hardkrafthardkraft Member Posts: 28

    Also, why do logs display but not the display texts which are right next to them?

  • hardkrafthardkraft Member Posts: 28

    @BBEnk, thanks for the effort.

    From I can see in the top box:

    • display shows the initial value: 0
    • timer gets triggered, will change the value to 1 after 5 secs
    • rule var1=1 does not get triggered yet since var1=0
    • after 5 secs var1 changes to 1
    • rule var1=1 gets triggered

    that’s pretty clear, thanks. Then would you say my code executes like this:

    • attribute changes to 1
    • display shows 1
    • rule var1 = 1 gets triggered
    • log displays 1
    • display inside the rule does not get triggered (why?)
    • attribute changes to 0
    • display shows 0

    Is my understanding correct?

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited October 2014

    I thought that once something is displayed it stays on the screen, it doesn’t display and then disappear.

    The reason it would change when adding the timers is that the timers triggering force it to update. If you are asking why doesn't your code display only a 1, again its probably because it changes from 1 to 0 so fast it never actually displays the 1 on screen.

    Besides, when I remove the bottom attr change everything displays as expected, why?

    Because you are never changing it to 0. If you change the bottom 0 to 100 it will display 100. Because it's the last Change to happen, it's what gets displayed.

    Also, why do logs display but not the display texts which are right next to them?

    Logs 'log' the action. Other action is too fast to display on screen I'm guessing...

    If you remove the very top display the screen will remain blank.

    Not sure why that happens....

  • hardkrafthardkraft Member Posts: 28

    @jamie_c said:
    If you are asking why doesn't your code display only a 1, again its probably because it changes from 1 to 0 so fast it never actually displays the 1 on screen.

    yes, this is the main mystery to me. I change it to 0 AFTER I’d expect it being displayed as 1 inside the rule. The debug does see it as 1 inside the rule and it’s not too fast, but somehow the display that’s right next to it doesn’t do anything. That’s what I don’t understand.

  • BBEnkBBEnk Member Posts: 1,764

    @hardkraft said:
    BBEnk, thanks for the effort.

    From I can see in the top box:

    • display shows the initial value: 0
      correct.
    
    • timer gets triggered, will change the value to 1 after 5 secs
     wrong, timer gets triggered after 5 seconds and then changes var1 to 1.
    
    • rule var1=1 does not get triggered yet since var1=0
      wrong, the rule now executes and runs because var1 is a 1.
    
    • after 5 secs var1 changes to 1
      wrong, its already a 1.
    
    • rule var1=1 gets triggered
      wrong, rule has already run. and after 5 more seconds it will change to 0.
    

    that’s pretty clear, thanks. Then would you say my code executes like this:

    • attribute changes to 1
    • display shows 1
    • rule var1 = 1 gets triggered
    • log displays 1
    • display inside the rule does not get triggered (why?)
     it did trigger but gamesalad executes your code so fast you only see the ending result a 0.
    
    • attribute changes to 0
    • display shows 0

    Is my understanding correct?

  • hardkrafthardkraft Member Posts: 28
    edited October 2014

    @BBEnk said:

    it did trigger but gamesalad executes your code so fast you only see the ending result a 0.

    OK, take my original project and remove the very top display. Now you’ll see that no displays inside the rule ever get triggered. Does that make sense?

    For clarification I’m posting the new project here. The only change is that I removed the top display (the cause of all the confusion). Now the text box remains blank.
    https://dropbox.com/s/xseaoiuccapf3xz/test1.gameproj.zip?dl=0

Sign In or Register to comment.