Page 1 of 1

Trouble with button script...

PostPosted: Tue Jan 27, 2009 11:32 am
by Teclis
This is last script that I must make to work before I can release my warhammer TC.
I have no exprience on using getbuttonpressed command (I have avoided it until now) so I don't know what to do about it.
This is probably piece of cake to someone who has any exprience with getbuttonpressed.

Code: Select all
Begin SeaSwordCommandScript


short button
short state
;global NavalBattle



if ( OnActivate == 1 )
       if ( state == 0 )
               if ( NavalBattle == 0 );Homeport
                       Messagebox "What do you want to do?" "Try to find enemy ships" "Nothing"
                       set state to 1
               else
                       Messagebox "Do you want to sail to homeport?" "Yes" "No"
                       set state to 1
endif
       endif
               endif

if ( state == 1 )
       set button to getbuttonpressed
endif

if ( button == -1 )
       return
endif

if ( button == 0 )
       if ( NavalBattle == 0 )
               Messagebox "Battle is ready"
               "SeaSwordDoor01"->disable
               "SeaSwordDoor02"->enable
               set NavalBattle to 1
               set state to 0
       elseif ( NavalBattle > 0 )
               Messagebox "Returning to home"
               "SeaSwordDoor02"->disable
               "SeaSwordDoor01"->enable
               set state to 0
else
       set state to 0
endif
       endif



end

Re: Trouble with button script...

PostPosted: Tue Jan 27, 2009 11:40 am
by Jac
Try this:

Code: Select all
Begin SeaSwordCommandScript


short button
short state
;global NavalBattle

if ( OnActivate == 1 )
  if ( state == 0 )
     if ( NavalBattle == 0 );Homeport
        Messagebox "What do you want to do?" "Try to find enemy ships" "Nothing"
        set state to 1
     else
        Messagebox "Do you want to sail to homeport?" "Yes" "No"
        set state to 1
       endif
  endif
endif

if ( state == 1 )
  set button to getbuttonpressed
       if ( button == -1 )
          return
       elseif ( button == 0 )
          if ( NavalBattle == 0 )
             Messagebox "Battle is ready"
             "SeaSwordDoor01"->disable
             "SeaSwordDoor02"->enable
             set NavalBattle to 1
             set state to 0
          elseif ( NavalBattle > 0 )
             Messagebox "Returning to home"
             "SeaSwordDoor02"->disable
             "SeaSwordDoor01"->enable
             set state to 0
       else
               set state to 0
          endif
        endif
endif

end


I may be missing an endif somewhere, I didn't run this through the compiler but it should work.

Re: Trouble with button script...

PostPosted: Tue Jan 27, 2009 12:27 pm
by Teclis
it worked for a first time. When I tried to sail back to home it didn't work.

Re: Trouble with button script...

PostPosted: Tue Jan 27, 2009 2:46 pm
by Fliggerty
I prefer to only ever set a variable inside of OnActivate.  It only ever returns true for one frame, and I find that is the most reliable way to make things work.  I also simplified it a small bit by only setting state to 0 in one place.  I don't see why this won't work more than once.

Code: Select all
Begin SeaSwordCommandScript


       short button
       short state
               ;global NavalBattle

       if ( OnActivate == 1 )
               set state to 1
       endif

       if ( state == 1 )
               if ( NavalBattle == 0 );Homeport
                       Messagebox "What do you want to do?" "Try to find enemy ships" "Nothing"
                       set state to 2
               else
                       Messagebox "Do you want to sail to homeport?" "Yes" "No"
                       set state to 2
               endif
       endif


       if ( state == 2 )
               set button to getbuttonpressed
               if ( button == -1 )
                       return
               elseif ( button == 0 )
                       if ( NavalBattle == 0 )
                               Messagebox "Battle is ready"
                               "SeaSwordDoor01"->disable
                               "SeaSwordDoor02"->enable
                               set NavalBattle to 1
                       elseif ( NavalBattle > 0 )
                               Messagebox "Returning to home"
                               "SeaSwordDoor02"->disable
                               "SeaSwordDoor01"->enable
                       endif
                       set state to 0
               endif
       endif

end

Re: Trouble with button script...

PostPosted: Wed Jan 28, 2009 7:12 am
by Teclis
It works perfectly. Now, I'll just have to make one exterior for the ship.