GetButtonPressed Returning -1
Posted: Thu Oct 13, 2016 12:32 pm
I'm having some strange problems with a chargen script that I've been modifying. In essence, the player chooses between three options for their starting area. If the player choose "random" then the script rolls the dice and activates a random region script while setting a global variable "CRELisRandom" to 1. The computer just randomly goes through the region script without any GetButtonPressed input. If the player chooses a specific region, then that specific script is activated and CRELisRandom stays at 0. Both the starting script and a region script are attached below.
When I select the "Random" option for starting area, it runs perfectly: it sets CRELisRandom to 1, runs that portion of CRELvvarden, and then places the player character in a random scenario with the HUD and everything activated.
When I select Vvardenfell for the starting area, CRELvvarden is activated and I proceed through the CRELisRandom == 0 portion until State 5. The problem arises here when I select either Caldera or Gnisis. Either option leads to the message "State 5 button -1" appearing indicating that the script thinks that I'm not selecting an option. After clicking either city, both scripts end and I'm stuck unable to move with no HUD (aka CRELoverallState doesn't get set to 1 in chargenew).
Additionally, selecting Random instead of Caldera or Gnisis ends up working perfectly as intended.
I hope this is an obvious error, but I'm struggling to see why GetButtonPressed is returning -1 in that portion of the script.
The starting script:
Spoiler
begin chargenew
short StartState
short State
short buttonLoc
short button
;short SkipPress
short RandStart
float WindowTimer ;Stops the windows from stacking (all coming up at the same time).
if ( WindowTimer < 1)
set WindowTimer to ( WindowTimer + GetSecondsPassed )
return
endif
if ( menumode == 1)
return
endif
if ( CRELoverallState == 0 )
...
elseif ( State == 60 )
if ( ScriptRunning, "CM_SpawnItem" == 0)
MessageBox "Where does your story begin?", "Random", "Vvardenfell", "Solstheim"
set State to 65
endif
return
elseif ( State == 65 )
set buttonLoc to GetButtonPressed
if ( buttonLoc == -1 )
return
elseif ( buttonLoc == 0 ) ;Random
set CRELisRandom to 1
set RandStart to ( Random, 2 )
if ( RandStart == 0 )
StartScript, CRELvvarden
elseif ( RandStart == 1 )
StartScript, CRELsolstheim
endif
elseif ( buttonLoc == 1 ) ;Vvardenfell
StartScript, CRELvvarden
elseif ( buttonLoc == 2 ) ;Solstheim
...
endif
return
elseif ( CRELoverallState == 1 ) ; activated region script sets CRELoverallState to 1 before ending
endif
end chargenew
The region script activated through the starting script
Spoiler
begin CRELvvarden
short OverallState
short State
short SkipPress ;Used only for Random beginning. Skips Getbuttonpress.
short RandStart1A
short RandStart1B
short RandStart2
short button
if ( menumode == 1 )
return
endif
if ( OverallState == 0 )
if ( CRELisRandom == 0 ) ; vvardenfell chosen in chargenew script
if ( State == 0 )
MessageBox "Under what circumstances does your story begin on Vvardenfell?", "Random", "Caldera", "Gnisis"
set State to 5
elseif ( State == 5 )
if ( SkipPress != 1 )
set button to GetButtonPressed
endif
if ( button == -1 )
MessageBox "State 5 button -1"
return
elseif ( button == 0 )
set RandStart1A to ( Random, 2 )
if ( RandStart1A == 0 )
set RandStart1B to ( ( Random, 2 ) + 1 )
set button to RandStart1B
elseif ( RandStart1A == 1 )
set RandStart1B to ( ( Random, 2 ) + 1 )
set button to RandStart1B
endif
elseif ( button == 1 )
...
set OverallState to 1
elseif ( button == 2 )
...
set OverallState to 1
endif
endif
elseif ( CRELisRandom == 1 ) ; random option chosen in chargenew script
set SkipPress to 1
set CRELisRandom to 0
set RandStart2 to ( Random, 2 )
if ( RandStart2 == 0 )
set State to 5
set button to ( ( Random, 2 ) + 1 )
elseif ( RandStart2 == 1 )
set State to 5
set button to ( ( Random, 2 ) + 1 ) ; same as above for debug purposes
endif
return
endif
elseif ( OverallState == 1 )
StopScript, CRELvvarden
endif
end CRELvvarden