Stumped on this
BlitzPlus Forums/BlitzPlus Beginners Area/Stumped on this
| ||
| I was just playing around with this test I made and I'm clueless to why the following error message pops up: "Case without Select." The code is properly indented for those who are adamant 'bout it.
;Event List
KEY_DOWN=$101 ;A key was pressed down-needs the keys scancode for EventData().
KEY_UP=$102 ;A key has been released on the keyboard-needs the keys scancode for EventData().
KEY_USED=$103 ;A key has been typed-needs keys ascii value.
MOUSE_BUTTON_DOWN=$201 ;self explanatory, needs one of the following values(1=left,2=middle,3=right).
MOUSE_OVER_CANVAS=$203 ;self explanatory, you need to use EventX() and EventY() along with the canvas handle.
GADGET_USED=$401 ;self explanatory, you need to be specific to what kind of gadget it is, and what the gadgets handle is as well.
MENU_SELECTED=$1001 ;something has been selected from a menu, needs the menu identifier
X_HIT=$803 ;The X was hit
APPLICATION_HALTED=$2001 ;Self explanatory, means that the program was suspended
APPLICATION_RESUMED=$2002 ;Self explanatory, means that the program was resumed
;Banks
guibank=CreateBank(12)
PokeInt guibank,0,CreateWindow("UNTILTLED TEST",300,300,400,400,main,15)
PokeInt guibank,4,CreateButton("1",35,35,35,35,main,1)
PokeInt guibank,8,CreateButton("2",70,70,70,70,main,1)
Repeat
Buttonz()
Until WaitEvent()=$803
End
Function Buttonz()
PeekInt(guibank,0)
uno=PeekInt(guibank,4)
dos=PeekInt(guibank,8)
Select WaitEvent()
Case $401
If EventSource()=uno Then
Notify("UNO")
Case $401
If EventSource()=dos Then
Notify("DOS")
EndIf
EndIf
End Select
End Function
Thanks, Siopses |
| ||
Im sure we told you off about your indentationFunction Buttonz()
PeekInt(guibank,0)
uno=PeekInt(guibank,4)
dos=PeekInt(guibank,8)
Select WaitEvent()
Case $401
If EventSource()=uno Then
Notify("UNO")
Case $401
If EventSource()=dos Then
Notify("DOS")
EndIf
EndIf
End Select
End Function Anyway the CASE inside the IF is not part of the select. It is part of the code block of the ifFunction Buttonz()
PeekInt(guibank,0)
uno=PeekInt(guibank,4)
dos=PeekInt(guibank,8)
Select WaitEvent()
Case $401
If EventSource()=uno Then
Notify("UNO")
ElseIf EventSource()=dos Then
Notify("DOS")
EndIf
End Select
End FunctionI ASSUME that you are going to add new "Cases" which is why I have left select in at all. |
| ||
| Ok thanks, but do I need to End those If's before I make more Case's? |
| ||
You must always close a scope when you're done with it. Always work in a > style.
start scope1
start scope2
end scope2
start scope3
start scope4
end scope4
end scope3
end scope 1
etc. |
| ||
| btw, there's another thing, but I don't know whether I should bug you with it now. But that Buttonz() function can only work with one bank, namely what you call 'guibank'. This guibank is neither a global or a function arguement, so you'll bump onto that bug sooner or later. Designwise you want one function to serve a multitide of banks, your current one is hardcoded. |
| ||
| Your bank idea does not work, because when I try to run my program the gadgets do not appear and it says that my group handle is invalid. |
| ||
| My bank idea works flawlessly, I've used it on tons of perfectly structured things, but you don't read what I wrote above your post. |
| ||
| So you make the gadget, then put the gadgets handle into the last part of PokeInt, like so:
window=CreateWindow("TEST",300,400,500,500,window,15)
button=CreateButton("CLICK",100,100,150,150,window,1)
guibank=CreateBank(8)
PokeInt guibank,0,window
PokeInt guibank,4,button
Repeat
Button()
Until WaitEvent()=$803
Function Button()
button=PeekInt(guibank,4)
Select WaitEvent()
Case $401
If EventSource()=button Then
Notify("Button hit")
EndIf
End Select
End Function
Also, the bank must be declared in the function it is used in right? Because it now says invalid bank handle. Well, I'll shove this idea and do what I was before which worked perfectly fine. |
| ||
| But the bank isn't declared in the function, it's declared outside in your main loop, or main source, or whatever it's called. :P Observe that Button function, you read from 'guibank' .. what's guibank? How does the function know what 'guibank' is? It can't know what it is as guibank is not a global, and it's also not a given argument. Solution: make it a global in your main, OR -and this is to be preferred- make it an argument for your Button function. |
| ||
| Thanks I guess it was naive of me to go out and say that, but for one, why would you need a bank for the gadgets if they are created in the function? |
| ||
| They are not created in the function. They're created at the start of your source, each 'thing' (bank, button, window, timer, image, sound etc.) has an int number. It's this number you store in the bank, and it's also this number you READ from that bank in the function. So, when you do button=PeekInt(guibank,4) in that function then you don't create a button there, you read out the int value of the button which you've created at the start of your source. The only thing you do is put that number into a new variable so that you can use that variable to access the button again. You don't even need a variable if you're a die-hard low-level junk. You can as well do: If EventSoure()=PeekInt(guibank,4) .. .. All you do with those banks is move numbers around your source. You could as well use an array, but they have the disadvantage of being global and they can't be defined locally in a function. That's where banks shine, you can really do everything with banks, create them locally, use them locally, wipe them locally.. resize them locally, all terrific stuff. :P |
| ||
Maybe this helps. *run it in debugmode*
window=CreateWindow("y00!",0,0,640,480)
DebugLog "intvalue of window = "+window
button=CreateButton("meep",0,0,64,24,window)
DebugLog "intvalue of button = "+button
slider=CreateSlider(0,40,64,24,window,1)
DebugLog "intvalue of slider = "+slider
canvas=CreateCanvas(40,90,64,24,window)
DebugLog "intvalue of canvas = "+canvas
bank=CreateBank(16)
DebugLog "intvalue of bank = "+bank
PokeInt bank,0 ,window
PokeInt bank,4 ,button
PokeInt bank,8 ,slider
PokeInt bank,12,canvas
GoToAFunction(bank)
Notify "done!"
End
Function GoToAFunction(anybank)
window=PeekInt(anybank,0 )
button=PeekInt(anybank,4 )
slider=PeekInt(anybank,8 )
canvas=PeekInt(anybank,12)
DebugLog "woops, we're in a function now!"
DebugLog "intvalue of window = "+window
DebugLog "intvalue of button = "+button
DebugLog "intvalue of slider = "+slider
DebugLog "intvalue of canvas = "+canvas
DebugLog "intvalue of bank = "+anybank
End Function
|
| ||
| More excitement: so a bank itself also has an int value, meaning you can also put a bank in a bank! |
| ||
| So its all right if the bank is outside the function? It'll still be usable? |
| ||
| Also CS_TBL your bank idea does have a problem, unfortunatly- Anyway, the problem is that you need to double click in order to have anything go through so even though the code is very clean... the menu's must be clicked on twice. How are you supposed to click on a menu twice? At any rate, 'm still using this idea for every thing else. Thanks, Siopses |
| ||
| So its all right if the bank is outside the function? It'll still be usable? That's a bit of a weird way to put it. You can declare anything you want, if you want to use it in a function, just make it a global (no good idea), or use it as function argument (preferred). As said, all these things are just numbers, it's all a matter of sending numbers around. One could also declare gadgets etc. in a function, put them in a bank declared in that function, and return that bank from that function. Also CS_TBL your bank idea does have a problem, unfortunatly- Anyway, the problem is that you need to double click in order to have anything go through so even though the code is very clean... Everything related to behaviour of gadgets is related to gadgets, not banks. Banks aren't witchcraft, they're the same as any other variable, only a bit more low-level. I bet there just another bug in the sourcecode :P |
| ||
Here's my source code:
;Event List
KEY_DOWN=$101 ;A key was pressed down-needs the keys scancode for EventData().
KEY_UP=$102 ;A key has been released on the keyboard-needs the keys scancode for EventData().
KEY_USED=$103 ;A key has been typed-needs keys ascii value.
MOUSE_BUTTON_DOWN=$201 ;self explanatory, needs one of the following values(1=left,2=middle,3=right).
MOUSE_OVER_CANVAS=$203 ;self explanatory, you need to use EventX() and EventY() along with the canvas handle.
GADGET_USED=$401 ;self explanatory, you need to be specific to what kind of gadget it is, and what the gadgets handle is as well.
MENU_SELECTED=$1001 ;something has been selected from a menu, needs the menu identifier
X_HIT=$803 ;The X was hit
APPLICATION_HALTED=$2001 ;Self explanatory, means that the program was suspended
APPLICATION_RESUMED=$2002 ;Self explanatory, means that the program was resumed
window=CreateWindow("UNTILTLED TEST",300,300,400,400,window,15)
uno=CreateButton("1",35,35,35,35,window,1)
dos=CreateButton("2",70,70,70,70,window,1)
menu=WindowMenu(window)
file=CreateMenu("File",1,menu)
finish=CreateMenu("End",2,file)
UpdateWindowMenu(window)
guibank=CreateBank(120)
PokeInt guibank,0,window
PokeInt guibank,4,uno
PokeInt guibank,8,dos
PokeInt guibank,12,file
PokeInt guibank,16,finish
Repeat
Buttonz(guibank)
Until WaitEvent()=$803
Notify("Ending...")
End
Function Buttonz(guibank)
window=PeekInt(guibank,0)
uno=PeekInt(guibank,4)
dos=PeekInt(guibank,8)
Select WaitEvent()
Case $401
If EventSource()=uno Then
Notify("UNO")
Else
If EventSource()=dos Then
Notify("DOS")
EndIf
EndIf
End Select
End Function
Function Menuz(guibank)
file=PeekInt(guibank,12)
finish=PeekInt(guibank,16)
Select WaitEvent()
Case $1001
If EventSource()=finish Then
Notify("See ya!")
Delay 500
End
EndIf
End Select
End Function
Any bugs? None that my eye's can detect, how about yours? |
| ||
| In my version you don't need to click things twice. And I added white lines. You *need* white lines as much as you need indenting. Having no white lines is like reading a line of text which has no commas. Remember this line: You only need a Waitevent() command once, in your main loop from which you call all your functions. You don't need it in any other fuctions, unless they're self-contained popup things like a color chooser, but you're far from that stage at this moment. So, you had Select Waitevent() in your functions, that was the cause of your double-click bug, why check again for events? You'd already done so in your mainloop. The waitevent() command doesn't need to be anywhere in your functions because it's not relevant having it there. Waitevent waits for an event, once that event has occured, some global variables are filled, these global variables are (actually they're presented as functions, but nevermind) EventSource(), EventID(), EventX(), EventY(), EventData() and perhaps some more, dunno, read the manual I'd say. :P So, once they've been filled you can just read them out in any function, no need for extra WaitEvent commands. Here's an improved version, regarding functionality and readability.
;Event List
KEY_DOWN=$101 ;A key was pressed down-needs the keys scancode for EventData().
KEY_UP=$102 ;A key has been released on the keyboard-needs the keys scancode for EventData().
KEY_USED=$103 ;A key has been typed-needs keys ascii value.
MOUSE_BUTTON_DOWN=$201 ;self explanatory, needs one of the following values(1=left,2=middle,3=right).
MOUSE_OVER_CANVAS=$203 ;self explanatory, you need to use EventX() and EventY() along with the canvas handle.
GADGET_USED=$401 ;self explanatory, you need to be specific to what kind of gadget it is, and what the gadgets handle is as well.
MENU_SELECTED=$1001 ;something has been selected from a menu, needs the menu identifier
X_HIT=$803 ;The X was hit
APPLICATION_HALTED=$2001 ;Self explanatory, means that the program was suspended
APPLICATION_RESUMED=$2002 ;Self explanatory, means that the program was resumed
window=CreateWindow("UNTILTLED TEST",300,300,400,400,window,15)
uno=CreateButton("1",35,35,35,35,window,1)
dos=CreateButton("2",70,70,70,70,window,1)
menu=WindowMenu(window)
file=CreateMenu("File",1,menu)
finish=CreateMenu("End",2,file)
UpdateWindowMenu(window)
guibank=CreateBank(120)
PokeInt guibank,0,window
PokeInt guibank,4,uno
PokeInt guibank,8,dos
PokeInt guibank,12,file
PokeInt guibank,16,finish
Repeat
WaitEvent() ; <- fixed
Buttonz guibank
Until EventID()=$803 ; <- fixed
Notify("Ending...")
End
Function Buttonz(guibank)
window=PeekInt(guibank,0)
uno=PeekInt(guibank,4)
dos=PeekInt(guibank,8)
Select EventID() ; <- fixed
Case $401
If EventSource()=uno Then ; fixed some here and below
Notify "UNO"
ElseIf EventSource()=dos Then
Notify "DOS"
EndIf
End Select
End Function
Function Menuz(guibank)
file=PeekInt(guibank,12)
finish=PeekInt(guibank,16)
Select EventID() ; <- fixed
Case $1001
If EventSource()=finish Then
Notify("See ya!")
Delay 500
End
EndIf
End Select
End Function
|
| ||
| Um CS_TBL, if you test your version it works the same as the version I made. I'm positive that's what it is... any alternate version doesn't work either. But it's odd... it only work's on menu's not list boxes or anything else. |
| ||
| The functionality might be the same, but in your version I had to click twice on buttons and menus in order to have them do something, you complained about this doubleclicking some posts above even. I tested/ran this fixed version and everything worked ok. |
| ||
| Well CS_TBL, I also tested and ran the code... the button's were good- and for that I thank you, but the menu problem is still very apparent. Also on Wazzup, can you believe they locked his ChatterBox thread. I told the kid this isn't a live chat room or anything around those line's, but sheesh! Was I that hard-headed when I was a 9 year-old? |
| ||
| nah, it had to be closed sooner or later, happens with all long threads. |
| ||
| btw, if you want that menu to work you have to call the function in that mainloop. I didn't fix that as it wasn't there in the original version either.. I mainly fixed things on sight :P |
| ||
| Even with the function in the main loop it didn't work. Oh well, that's all right. Thanks, Siopses |
| ||
Ah, rite, btw you could've checked the manual as well eh, there's a clear menu example in there.
Select EventID() ; <- fixed
Case $1001
If EventData()=2 Then
Notify("See ya!")
Delay 500
End
EndIf
End Select
You don't use the 'finish' stuff really, you use the ID you give when creating that menus. So, why use this <variable>=CreateMenu ? Simple: you might want to have menus to check or uncheck, then it's handy when you can actually access them using a variable/handle. |
| ||
| The 'chatterbox' thread was closed at 150 posts.. maybe that is the maximal number of posts a thread may contain ? |
| ||
| yeah, i think its 150 posts. |