Talk:GetButtonPressed

From the Oblivion ConstructionSet Wiki
Revision as of 00:48, 8 December 2007 by imported>Haama (Not quite what I meant, let me try again)
Jump to navigation Jump to search

The example script does an infinite loop. Because the GetButtonPress is in GameMode, it will keep getting the button pressed over and over, thus displaying the final dialog over and over again. I edited the code to fix this error. --Snarker 22:27, 7 December 2007 (EST)

I switched the buttonpressed flags. When a mod is first loaded in the game, every object's script runs once. When a variable is set on an object, it will run the next frame. The way it was set up before, it would continue to use GetButtonPressed until the player enters a MenuMode. In this particular case it's minor, but it can add up and is a good habit to re-enforce.--Haama 23:12, 7 December 2007 (EST)
Actually the original script was fine; getButtonPressed returns a value other than -1 only once per message box. But your revised script shows the intention more clearly. Scruggs 23:15, 7 December 2007 (EST)
But that's not it, I'm talking about it running when it hasn't even been activated. Every object, persistent and non-persistent, runs when you first enter the game (I think it's only when the mod has first been loaded, I don't remember if I tested that). So, on that first frame
begin GameMode
if buttonpressed == 0
  set button to getbuttonpressed

would run. To make it (to be clear, I'm no longer talking about GetButtonPressed except as an example) even worse, every time a variable on the object is set, the object runs the next frame. So the part of the code above continues running until the player enters a MenuMode.

If you really want to play some games, create a non-persistent object somewhere in the world (might have to be an interior), and attach this script
short Working
begin MenuMode
  set Working to 0
  message "Hello World"
end