Difference between revisions of "MessageBox Tutorial"

7 bytes added ,  11:13, 29 August 2007
m
imported>Haama
imported>Haama
Line 183: Line 183:


===Running the same choice for multiple frames===
===Running the same choice for multiple frames===
So far, we've set up the button catching section like this:
So far, we've been using GetButtonPressed like this:
<pre>...
<pre>...
   elseif (Choosing == 1)
   elseif (Choosing == 1)
Line 194: Line 194:
<pre>...
<pre>...
   elseif (Choosing == -1)
   elseif (Choosing == -1)
     messagebox "What would you like to do?" "Duplicate everything" "Nothing"
     messagebox "What would you like to do?" "Count food" "Nothing"
     set Choosing to 1
     set Choosing to 1
     set Choice to GetButtonPressed
     set Choice to GetButtonPressed
Line 201: Line 201:
     if (Choice == -1)
     if (Choice == -1)
       return
       return
     elseif (Choice == 0) ;Duplicate items one by one from the player, into a container
     elseif (Choice == 0) ;Count the number of food items in the player's possession
       set InvPos to (InvPos + 1)
       set InvPos to (InvPos + 1)
       set pInvObj to (player.GetInventoryObject
       set pInvObj to (player.GetInventoryObject
       pContainer.AddItem pInvObj 1
       if (IsFood pInvObj)
        set FoodCount to (FoodCount + 1)
      endif
       ...
       ...
     elseif (Choice == 1) ;Nothing
     elseif (Choice == 1) ;Nothing
Line 210: Line 212:
     endif
     endif
...</pre>
...</pre>
"Duplicate Everything" requires several frames to complete. Once GetButtonPressed returns the player's choice, it will start off and add the first item to the container. However, on the following frames GetButtonPressed will return -1, causing an infinite loop of 'if (Choice == -1) -> return'. To prevent this, only run GetButtonPressed when it had previously returned -1:
"Count food" requires several frames to complete. Once GetButtonPressed returns 0, it will start off and test the first item. However, on the following frames GetButtonPressed will return -1, causing an infinite loop of ''if (Choice == -1) -> return''. To prevent this, only run GetButtonPressed when it had previously returned -1:
<pre>...
<pre>...
   elseif (Choosing == -1)
   elseif (Choosing == -1)
     messagebox "What would you like to do?" "Duplicate everything" "Nothing"
     messagebox "What would you like to do?" "Count food" "Nothing"
     set Choosing to 1
     set Choosing to 1
     set Choice to -1
     set Choice to -1
Line 219: Line 221:
     if (Choice == -1)
     if (Choice == -1)
       set Choice to GetButtonPressed
       set Choice to GetButtonPressed
     elseif (Choice == 0) ;Duplicate items one by one from the player, into a container
     elseif (Choice == 0) ;Count the number of food items in the player's possession
       set InvPos to (InvPos + 1)
       set InvPos to (InvPos + 1)
       set pInvObj to (player.GetInventoryObject
       set pInvObj to (player.GetInventoryObject
       pContainer.AddItem pInvObj 1
       if (IsFood pInvObj)
        set FoodCount to (FoodCount + 1)
      endif
       ...
       ...
     elseif (Choice == 1) ;Nothing
     elseif (Choice == 1) ;Nothing
Line 228: Line 232:
     endif
     endif
...</pre>
...</pre>
Note that Choice is reset to -1 after displaying a menu. Otherwise, Choice would still be the same as for the last menu (let's say the player choose 0). This would not be -1, so GetButtonPressed would never be run, and that Choice (0) would run instead of the player's choice.
Note that Choice is reset to -1 after displaying a menu. Otherwise, Choice would still be the same as for the last menu (0, in this case). GetButtonPressed would never be run because Choice isn't equal to -1, and that Choice (0) would run instead of the player's choice.


==Creating Your New Menu==
==Creating Your New Menu==
Anonymous user