Page 1 of 1

Only 1 procedure will run, why?

Posted: Wed Jun 10, 2009 4:29 am
by Hot Pockets
When I try to run the program below only 1 Procedure will Display. If I run it as is the 1st procedure will run correctly. If rmark out either 1 the Other will run correctly. I don't understand it but then I don't know Purebasic. Please elighten me!! :roll:

Code: Select all

Declare SplashScr()
Declare MainMenu()
Enumeration
  #WIN_MAIN
  #IMAGE_FILE
  #IMAGE_DISPLAY
EndEnumeration
Global Quit.b = #False

SplashScr()

MainMenu() 

Procedure SplashScr()
#FLAGS = #PB_Window_BorderLess | #PB_Window_ScreenCentered
If OpenWindow(#WIN_MAIN, 0, 0, 1024, 768, "Image", #FLAGS)
  If LoadImage(#IMAGE_FILE, "StarMap3.bmp")
     ImageGadget(#IMAGE_DISPLAY, 0, 0, 1024, 768, ImageID    (#IMAGE_FILE))
     StartTime = ElapsedMilliseconds()             ; Get the actual value
     Delay(1000)                                   ; Wait 1000 milliseconds
     ElapsedTime = ElapsedMilliseconds()-StartTime ; 'ElapsedTime' value should be about
     Quit = #True 
  EndIf
EndIf
CloseWindow(Image)
 MainMenu.s() 
EndProcedure
  ; Create the menu. The indent is very important here for a good lisibility
Procedure MainMenu()  
#Result = #PB_Window_TitleBar | #PB_Window_ScreenCentered
 OpenWindow(1, 0, 0, 1024, 768, "Command")
  If CreateMenu(1, WindowID(1))
    MenuTitle("File")
      MenuItem( 1, "&Load...")
      MenuItem( 2, "Save")
      MenuItem( 3, "Save As...")
      MenuBar()
      OpenSubMenu("Recents")
        MenuItem( 5, "Pure.png")
        MenuItem( 6, "Basic.jpg")
        OpenSubMenu("Even more !")
          MenuItem( 12, "Yeah")
        CloseSubMenu()
        MenuItem( 13, "Rocks.tga")
      CloseSubMenu()
      MenuBar()
      MenuItem( 7, "&Quit")

    MenuTitle("Edition")
      MenuItem( 8, "Cut")
      MenuItem( 9, "Copy")
      MenuItem(10, "Paste")
      
    MenuTitle("?")
      MenuItem(11, "About")

  EndIf
  
  DisableMenuItem(1, 3, 1)
  DisableMenuItem(1, 13, 1)
  ; This is the 'event loop'. All the user actions are processed here.
  Repeat

    Select WaitWindowEvent()
      Case #PB_Event_Menu
        Select EventMenu()  ; To see which menu has been selected
          Case 11 ; About
            MessageRequester("About", "Cool Menu example", 0)
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
        EndSelect
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
  Until Quit = 1
EndProcedure

End
Edited by Berikco, added code tags

Posted: Wed Jun 10, 2009 6:16 am
by pdwyer
[ code ] tags please, it's very hard to read

Thanks

Posted: Wed Jun 10, 2009 7:14 am
by rrpl
Main problem appears to be you have "Quit = #True" in the Procedure SplashScr(). Delete this as its not needed and you should be fine. :)

I can see some other problems in the code also but they shouldn't stop it working, so give it a close look over. If you want me to tell you, let me know.

Posted: Wed Jun 10, 2009 8:07 am
by zikitrake
rrpl wrote:Main problem appears to be you have "Quit = #True" in the Procedure SplashScr(). Delete this as its not needed and you should be fine. :)

I can see some other problems in the code also but they shouldn't stop it working, so give it a close look over. If you want me to tell you, let me know.
quit is defined as Global, so in the sencond procedure this var = #true... you can try

Code: Select all

Procedure MainMenu()
	#quit = #false ;<----------------------- INITIALIZE THIS VAR AGAIN
	#Result = #PB_Window_TitleBar | #PB_Window_ScreenCentered
	OpenWindow(1, 0, 0, 1024, 768, "Command")
	If CreateMenu(1, WindowID(1))
		MenuTitle("File")
....

Why doesn't it run?

Posted: Wed Jun 10, 2009 5:51 pm
by Hot Pockets
Thanks
I was surprised that there was other erros in code as code was written by someone else and I just modified it, sustituting my StarMap.bmp file for theirs

Posted: Wed Jun 10, 2009 8:01 pm
by Trond
Please think about it for a while. It's not errors in the two pieces of code. But they don't work together like you expect them to, because both expects Quit to be 0, but the first sets it to 1, so when the second procedure is reached it quits immediately.