Jump to content

MessageBox, what am I doing wrong?


Recommended Posts

I read the messagebox tutorial and here is the script for an activator I put in my mod.

 

As you can see it pretty much the same from the tutorial, and I thought I got the logic, but I am obviously missing something.

 

In fact when I activate the script the messagebox appear, but when I click in a option nothing happens a part of closing the messagebox.

scn ezzeMenuScript
 
Short Working
Short Choosing
Short Choice
 
 
 
Begin onActivate
  Set Choosing to -1
  Set Working to 1
End
 
 
 
Begin GameMode
  If Working
    Set Working to 1
 
    If (Choosing == 0) ;meaning it shouldn't be running
      Set Working to 0
      ;Add anything that needs to be re-initialized
 
    Elseif (Choosing == -1) ;Display your menu
      Messagebox "TEST" "zero" "one" "two" "three" "four" "five"
      Set Choosing to 1
      Set Choice to -1
 
    Elseif (Choosing == 1) ;Catch the player's decision
      If (Choice == -1) ;No choice yet
        Set Choice to GetButtonPressed
 
      Elseif (Choice == 0)
        Message "Choice 0"
        Set Choosing to 0
 
      Elseif (Choice == 1)
        Message "Choice 1"
        Set Choosing to 0
 
      Elseif (Choice == 2)
        Message "Choice 2"
        Set Choosing to 0
 
      Elseif (Choice == 3)
        Message "Choice 3"
        Set Choosing to 0
 
      Elseif (Choice == 4)
        Message "Choice 4"
        Set Choosing to 0
 
      Elseif (Choice == 5)
        Message "Choice 5"
        Set Choosing to 0
      Endif
    Endif
  Endif
End
Edited by zdswulyx
Link to comment
Share on other sites

I do not have access to the CS at the moment, but the script looks somewhat right, I think. People write different sorts of things for it, but the main idea is (the tutorial probably also said it) to:

  • display a MessageBox with options -> game goes into MenuMode
  • player clicks a button -> MessageBox closes, game enters GameMode
  • in one of the frames following the closing of the MessageBox, the GetButtonPressed command returns the pressed button once
  • grab the button, if it is > -1, the do stuff

Maybe it is just something minor in your script. Considering how displaying the messagebox and grabbing the button variable are separate actions of sorts, have you tried splitting the script in half, to the OnActivate and GameMode blocks, to make it easier to work on (more "straightforward", with OnActivate first, GameMode following it:

ScriptName ezzeMenuScript

Short Choice
Short Activated

Begin OnActivate PlayerRef

    ; do all preperational initialisations HERE

    set Activated to 1
    Messagebox "TEST" "zero" "one" "two" "three" "four" "five"

End

Begin GameMode

    If ( Activated == 0 )
        Return
    EndIf

    set Choice to GetButtonPressed

    If ( Choice < 0 )
        Return
    EndIf

    set Activated to 0

    If ( Choice == 0 )
        Message "Choice 0"
    Elseif ( Choice == 1 )
        Message "Choice 1"
    Elseif ( Choice == 2 )
        Message "Choice 2"
    Elseif ( Choice == 3 )
        Message "Choice 3"
    Elseif ( Choice == 4 )
        Message "Choice 4"
    Elseif ( Choice == 5 )
        Message "Choice 5"
    EndIf

End

Hopefully that helps a little.

Link to comment
Share on other sites

hi Zd

 

L is here to help ( I am pretty super ultra bored --- right now I'm resizing all of my texture for better performance with nifty tools called Ordenador )

scn aogOSDoorCrypt

Short showMenu
Short choice

Begin onActivate
	Let showMenu := 1
	
	;Add anything that needs := be re-initialized
	MessageBoxEX "Hello World !|zero|one|two|three|four|five"
	
End

Begin GameMode
	if showMenu
		Let choice := GetButtonPressed ;always try to get button press, user input

		if choice != -1 ;watch the user decision, and do some action if any menu button get pressed
			
			Let showMenu := 0 ;stop the menu checker after user choosed
			
			if choice == 0
				MessageEX "choice %g" choice
			elseif choice == 1
				MessageEX "choice %g" choice
			elseif choice == 2
				MessageEX "choice %g" choice
			elseif choice == 3
				MessageEX "choice %g" choice
			elseif choice == 4
				MessageEX "choice %g" choice
			elseif choice == 5
				MessageEX "choice %g" choice
			endif
			
		endif
		
	endif
End
Edited by lubronbrons
Link to comment
Share on other sites

Nothing seems to work, I wonder if I am missing something totally different... :S

 

Obviously the executed script is the expected one, because I see the different messagebox (TEST and Hello World), but once I click the message close and nothing happens. According to the tutorial it's possible it is related to the fact that Activators must kept loaded. But even adding a dummy assignment as it's suggested there nothing changes. :S

 

Edit, I tried to simplify as much as possible... nothing.

scn ezzeLuggageMenuScript
 
Short Working
Short Choosing
Short Choice
 
 
Begin onActivate
  Set Choosing to 0
  Set Working to 1
End
 
 
Begin GameMode
  If Working == 1
 
    Set Working to 1 ;ensure the script continues as it''s doing something
 
    If Choosing == 0
      ; Display menu
      Messagebox "TEST3" "zero" "one" "two" "three" "four" "five"
      Set Choosing to 1
      Set Choice to -1
 
    ElseIf Choosing == 1
      ; Catch the player''s decision
      If (Choice < 0) ;No choice yet
        Set Choice to GetButtonPressed
        Return
      EndIf
 
      Set Choosing to -1
      Message "Choice %.0f " Choice
 
    ElseIf Choosing < 0
      ; Stop the script
      Set Working to 0
 
    Endif
 
  Endif
  ; if Working < 0 the script stops after one frame of doing nothing
End
Edited by zdswulyx
Link to comment
Share on other sites

hey

I thought you are going to use this for one time event

well now I know you want persistant menu

so the code should be like this

scn ezzeMenuScript

Short showMenu
Short choice

Begin onActivate
	Let showMenu := 1
	
	;Add anything that needs to be re-initialized
	MessageBoxEX "Hello World !|zero|one|two|three|four|five|Exit Menu" ;---> notice the different I add new 7th 'Exit Menu'
	
End

Begin GameMode
	if showMenu
	
		Let choice := GetButtonPressed ;always try to get button press, user input

		if choice != -1 ;watch the user decision, and do some action if any menu button get pressed

			if choice == 6
				MessageEX "bye bye"
				Let showMenu := 0 ;exit infinite loop, stop the menu checker after user choose 'Exit Menu'
			else
				if choice == 0
					MessageEX "choice %g" choice
				elseif choice == 1
					MessageEX "choice %g" choice
				elseif choice == 2
					MessageEX "choice %g" choice
				elseif choice == 3
					MessageEX "choice %g" choice
				elseif choice == 4
					MessageEX "choice %g" choice
				elseif choice == 5
					MessageEX "choice %g" choice
				endif
				MessageBoxEX "Hello World !|zero|one|two|three|four|five|Exit Menu" ;---> notice the different I add new 7th 'Exit Menu'
			endif
			
		endif
		
	endif
End
Edited by lubronbrons
Link to comment
Share on other sites

I am not sure we are in the same page, I tried to put some messages:

scn ezzeMenuScript
 
Short Working
Short Choosing
Short Choice
Short ShowModeOnce
 
 
Begin onActivate
  Set Choosing to 0
  Set Working to 1
  Set ShowModeOnce to 1
   message "OnActivate!" ;;;THIS APPEARS
End
 
 
Begin GameMode
  If Working == 1
    Set Working to 1 ;ensure the script continues as it''s doing something
 
    if ShowModeOnce == 1
        message "GameMode!" ;;;THIS APPEARS
        Set ShowModeOnce to 2
    endIf
 
    If Choosing == 0
      ; Display menu
      Messagebox "TEST3" "zero" "one" "two" "three" "four" "five"
      Set Choosing to 1
      Set Choice to -1
 
    ElseIf Choosing == 1
      ; Catch the player''s decision
 
    if ShowModeOnce == 2
        message "Choosing == 1!" ;; THIS DOES NOT APPEAR!
        Set ShowModeOnce to 3
    endIf
 
 
      If (Choice < 0) ;No choice yet
        Set Choice to GetButtonPressed
        Return
      EndIf
 
 
    if ShowModeOnce == 3
        message "Choice done!" ;; THIS DOES NOT APPEAR EITHER!
        Set ShowModeOnce to 4
    endIf
 
 
      Set Choosing to -1
      Message "Choice %.0f " Choice
 
    ElseIf Choosing < 0
      ; Stop the script
      Set Working to 0
 
    Endif
 
  Endif
  ; if Working < 0 the script stops after one frame of doing nothing
End
I am not sure what's going. The variable Choosing is clearly set to one after displaying the menu. Edited by zdswulyx
Link to comment
Share on other sites

well...

I suggest you try my script first. and there is two version of it, my first script is for one-time-event and the second is for infinite loop menu chooser (must choose Exit to quit the infinite loop cycle)

if you still insist with your first script it will not work

here's my thought

 

1. there's no need to set this again and again if you know that this value already 1

Set Working to 1 ;ensure the script continues as it''s doing something

2. you need to get value with syntax 'GetButtonPressed'

so don't bury that syntax too deep like just you did

it's better that syntax must be run first after validation like this

if showMenu
	MessageBoxEX "Hello World !|zero|one|two|three|four|five|Exit Menu" ;---> notice the different I add new 7th 'Exit Menu'
	Let choice := GetButtonPressed ;always try to get button press, user input
Link to comment
Share on other sites

Actually the variable is set up again and again for a reason. Assuming the tutorial is right of course, it's needed to ensure the script continue working.

About your script, I tried the first version and I have the same problem as I posted in a previous message. Besides are you sure that MessageBoxEx has to be called every frame?

It is true I did not try the second, but it looks as the first a part that the menu is repeated.

Edited by zdswulyx
Link to comment
Share on other sites

quote : " but it looks as the first a part that the menu is repeated. "

A : that is intentional since you not use paging aren't you ?

if you use paging function the whole code is different and a little bit much more difficult

repeated action on show MessageBox is no problem

you'll see it yourself if you try that

 

EDIT : maximum menu in one page is 10 menu

so you can do it like this

MessageBoxEX "Hello World !|zero|one|two|three|four|five|six|seven|eight|nine"

if you do this, it may become something unsightly

MessageBoxEX "Hello World !|zero|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve" ;---> this is not recommended, menu more than 10 in one message box
Edited by lubronbrons
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...