Difference between revisions of "MessageBox Tutorial"

Jump to navigation Jump to search
7 bytes added ,  11:13, 29 August 2007
m
imported>Haama
imported>Haama
 
===Running the same choice for multiple frames===
So far, we've setbeen upusing the button catching sectionGetButtonPressed like this:
<pre>...
elseif (Choosing == 1)
<pre>...
elseif (Choosing == -1)
messagebox "What would you like to do?" "DuplicateCount everythingfood" "Nothing"
set Choosing to 1
set Choice to GetButtonPressed
if (Choice == -1)
return
elseif (Choice == 0) ;DuplicateCount itemsthe onenumber byof onefood fromitems in the player, into a's containerpossession
set InvPos to (InvPos + 1)
set pInvObj to (player.GetInventoryObject
pContainer.AddItemif pInvObj(IsFood 1pInvObj)
set FoodCount to (FoodCount + 1)
endif
...
elseif (Choice == 1) ;Nothing
endif
...</pre>
"DuplicateCount Everythingfood" requires several frames to complete. Once GetButtonPressed returns the player's choice0, it will start off and addtest 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:
<pre>...
elseif (Choosing == -1)
messagebox "What would you like to do?" "DuplicateCount everythingfood" "Nothing"
set Choosing to 1
set Choice to -1
if (Choice == -1)
set Choice to GetButtonPressed
elseif (Choice == 0) ;DuplicateCount itemsthe onenumber byof onefood fromitems in the player, into a's containerpossession
set InvPos to (InvPos + 1)
set pInvObj to (player.GetInventoryObject
pContainer.AddItemif pInvObj(IsFood 1pInvObj)
set FoodCount to (FoodCount + 1)
endif
...
elseif (Choice == 1) ;Nothing
endif
...</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's0, sayin thethis player choose 0case). ThisGetButtonPressed would notnever be -1,run sobecause GetButtonPressedChoice wouldisn't neverequal beto run-1, and that Choice (0) would run instead of the player's choice.
 
==Creating Your New Menu==
Anonymous user

Navigation menu