Help me, BlitzPlus

Blitz3D Forums/Blitz3D Beginners Area/Help me, BlitzPlus

Apollonius(Posted 2003) [#1]
Well, I got this code problem, I turned my little proggy into a popup spammer by accident, don't try this at home,
its kind of annoying :|

So I was trying the SelectedGadgetItem that soja told me to look at for my question on how to know what tabber the user selected so I came out with this piece of buggy code :D

Code Below
If file_open = True Then

  mainTabber=CreateTabber( 0,0,w,h,WinHandle )
 SetGadgetLayout mainTabber,1,1,1,1
 InsertGadgetItem(mainTabber,0,"0")
 InsertGadgetItem(mainTabber,1,"1")
 InsertGadgetItem(mainTabber,2,"2")
 UpdateWindowMenu WinHandle

  Tabber = SelectedGadgetItem( mainTabber )
  Messager = 0
 Select Tabber

    Case 0
    If Messager = 0 Then
    Notify "Tabber 1"
    Messager = messager + 1
    EndIf

    Case 1
    If Messager = 1 Then
    Notify "Tabber 1"
    Messager = messager + 1
    EndIf

    Case 2
    If Messager = 2 Then
    Notify "Tabber 1"
    Messager = messager + 1
    EndIf

 End Select
EndIf


I have no clue what so ever on what I did wrong :|
The code is in My main program loop.

Problem is:
it keeps poping popups when its at the last tabber "layers". But the number should be 3 on the messager variable, and the popup should only appear when the variable is 2 not 3.


Apollonius(Posted 2003) [#2]
Or wait!
Is it because I put message = 0 in my main loop so it always change it back to 0?

Edited,I even tryed this:
  Tabber = SelectedGadgetItem( mainTabber )
 Select Tabber

    Case 0
    If Messager = 1 Then
    Notify "Tabber 1"
    Messager = 0
    EndIf

    Case 1
    If Messager = 1 Then
    Notify "Tabber 2"
    Messager = 0
    EndIf

    Case 2
    If Messager = 1 Then
    Notify "Tabber 3"
    Messager = 0
    EndIf

 End Select
EndIf

I moved the variable out of the loop, now it only does it one time popup, no popup when i click on the other tabbers :(
Help?


-----------------------------------------------------------
ANother thing not working,
Im trying to disable menu and enable certain menu when i want them to:

...
CreateMenu "About",8,help
;----------------
UpdateWindowMenu WinHandle
 Messager = 0
 map_able = MenuEnabled(map)
 layers_able = MenuEnabled(layers)
;----------------
; MAIN LOOP
;----------------
Repeat
;----------------------------
; File Not Open, Menu Closed
If file_open = False Then

 If map_able = True Then
  DisableMenu map
 EndIf

 If layers_able = True Then
  DisableMenu layers
 EndIf

EndIf

; File Open, Menu Able
If file_open = True Then

 If map_able = False Then
  EnableMenu map
 EndIf

 If layers_able = False Then
  EnableMenu layers
 EndIf

EndIf
UpdateWindowMenu WinHandle
...

Help?


soja(Posted 2003) [#3]
I suggest changing your code a bit to make things easier in the long run.

It looks like you're checking every single time through your main loop what the currently selected tabber is, and then doing something with that. This might be easier:

1) Before your main loop, when you're creating your GUI, set the selected tabber to the one you want initially selected (probably 0, i.e. the first one, which is the default).
Remember that in a global variable or something, like "SelectedTabber%".

2) Only change "SelectedTabber" when the user clicks on a tabber and manually changes it. That way you don't have to constantly check which one is selected. You will know when a user selects a tabber because it will fire off a GadgetAction event.
So, in your WaitEvent() loop, check to see if the event was a GadgetAction event ($401). If so, then check to see if the EventSource() returns your mainTabber gadget. If so, then we can look at EventData() and it will return which tab page the user clicked on (0, 1, 2, etc). Then you can say "SelectedTabber = EventData()". You can also change anything else you want at this time regarding new tab pages.

This way you only have to deal with tab stuff when the user actually clicks on a tab, and not during every frame of your game or whatever. If you use the WaitEvent loop right, then it keeps CPU usage down to a minimum.


Apollonius(Posted 2003) [#4]
soja i sent you a email check it please, :|


soja(Posted 2003) [#5]
Kaisuo, it will be much easier for you if you rearrange your program to do something like this:

1) Create all your GUI stuff first
2) Write an Event loop that handles everything
3) Keep other stuff out of your loop if it doesn't have to do with handling events.

Right now, your event loop is only checking for two kinds of events -- CloseWindow and Menu events. You're then trying to handle all the other stuff after the event checks in the part marked "Program". This muddles up your code and is making it very difficult for you. For instance, in your menu handler, you check to see if the menu ID that was clicked on is 1. If it is, you set the flag "newfile" to true. Later on in your loop, you check to see if "newfile" is 1, and if it is, you make create a file called "temp.bm" and set "newfile" back to 0. Worse, this code gets checked every time any event happens (i.e. every time WaitEvent() catches any event). Why don't you just put the one line that calles the makefile function in the menu handler for case 1? That way it will only ever be called when that menu is chosen.

What will be easiest and neatest for you is to have your entire loop made up of JUST event handler stuff, i.e.:
While WaitEvent()
    Select EventID()
        Case thisevent
            do this
        Case thatevent
            do that in something else
        Case anotherevent
            call a function
    End Select
Wend

In other words, that loop, with all the appropriate functions and initialization code makes up your entire program. If you have it structured like this, it's very easy to fill in the blocks.

And remember, whenever the user clicks on a tab, WaitEvent will fail and EventID will be the GadgetAction event ($401). So then you just check for it there, and then inside of that you just check what tab was clicked, and then you can do whatever you want.

Welcome to the world of event-based programming. I'll send you some barebones BlitzPlus code via email.