Difference between revisions of "Talk:GetButtonPressed"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Scruggs
imported>Speedo
(changes)
 
(11 intermediate revisions by 4 users not shown)
Line 4: Line 4:


: 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. [[User:Scruggs|Scruggs]] 23:15, 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. [[User:Scruggs|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 [[Talk:Script_Processing#Problem with specific assertions|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
<pre>begin GameMode
if buttonpressed == 0
  set button to getbuttonpressed</pre>
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
<pre>short Working
begin MenuMode
  set Working to 0
  message "Hello World"
end</pre>--[[User:Haama|Haama]] 00:49, 8 December 2007 (EST)
:::Yes Haama I can confirm your observations. I remember well the discussion we had on this topic, in regards to this particular oddity I've noticed in my mod : a debug message (that I've scripted in this exact manner) was displaying right away from the game's main menu, before even having loaded or started any game, right after all the mods are loaded by the game engine. You came out with the same conclusion after some thoughts, I've tested it in my mod, and that's that. The solution is to provide an enclosing if statement (a simple example would be for verifying a flag dictating the GameMode block execution), within which no var set is done. Thanks again btw!
:::--[[User:HawkFest|HawkFest]] 07:35, 24 December 2007 (EST)
As already said, the code had an error in it.
<pre>begin gamemode
      if buttonPressed == 1
                set button to getbuttonpressed
      endif
if button > -1
...
</pre>
Since "button" starts life with a value of 0, "button > -1" always evaluates to true and as such the if block executes from the first time the script is loaded, creating an infinite loop.
I've changed the if condition now so it only evaluates to true if "button > -1" AND "buttonPressed == 1" are true.
--[[User:Draco Zandros|Draco Zandros]] 21:31, 3 January 2009 (EST)
:I just went ahead and tweaked the script slightly.  There's no reason not to nest the button evaluations under then buttonPressed condition, as that's the only time they need to be processed.
:--[[User:Speedo|Speedo]] 00:36, 4 January 2009 (EST)
== Origin of Spell/NPC script overlap ==
The note comes from findings in [http://www.bethsoft.com/bgsforums/index.php?s=&showtopic=783659&view=findpost&p=11385317 this thread].
== Frame count on GetButtonPressed returning a value ==
Is the 15-20 frame count outdated?  I've used the function a lot and 15-20 seems much higher than what the actual number is.<br>
--[[User:Quetzilla|quetzilla]] 17:01, 12 August 2008 (EDT)
:It still holds true for me - I guess the difference is computer by computer.--[[User:Haama|Haama]] 19:54, 12 August 2008 (EDT)

Latest revision as of 00:36, 4 January 2009

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

--Haama 00:49, 8 December 2007 (EST)

Yes Haama I can confirm your observations. I remember well the discussion we had on this topic, in regards to this particular oddity I've noticed in my mod : a debug message (that I've scripted in this exact manner) was displaying right away from the game's main menu, before even having loaded or started any game, right after all the mods are loaded by the game engine. You came out with the same conclusion after some thoughts, I've tested it in my mod, and that's that. The solution is to provide an enclosing if statement (a simple example would be for verifying a flag dictating the GameMode block execution), within which no var set is done. Thanks again btw!
--HawkFest 07:35, 24 December 2007 (EST)

As already said, the code had an error in it.

begin gamemode
       if buttonPressed == 1
                set button to getbuttonpressed
       endif

	if button > -1
...

Since "button" starts life with a value of 0, "button > -1" always evaluates to true and as such the if block executes from the first time the script is loaded, creating an infinite loop.

I've changed the if condition now so it only evaluates to true if "button > -1" AND "buttonPressed == 1" are true. --Draco Zandros 21:31, 3 January 2009 (EST)

I just went ahead and tweaked the script slightly. There's no reason not to nest the button evaluations under then buttonPressed condition, as that's the only time they need to be processed.
--Speedo 00:36, 4 January 2009 (EST)

Origin of Spell/NPC script overlap[edit source]

The note comes from findings in this thread.

Frame count on GetButtonPressed returning a value[edit source]

Is the 15-20 frame count outdated? I've used the function a lot and 15-20 seems much higher than what the actual number is.
--quetzilla 17:01, 12 August 2008 (EDT)

It still holds true for me - I guess the difference is computer by computer.--Haama 19:54, 12 August 2008 (EDT)