Global Lables?
Blitz3D Forums/Blitz3D Beginners Area/Global Lables?
| ||
Hi folks, i have set out a program in the following style: ;initialise graphics and declare global variables etc .mainloop ; main loop stuff in here now, in one of my included files, i have the player death function, which obviously is called when the player dies. It flushes all the data from the global variables adn then (should) go to the 'mainloop' label. I use the : goto mainloop : function, but whenever i try it i get an 'undefined label' error. do i have to delcare it somewhere first? i have tried: global .mainloop but it hates it :( can anyone give me some advice plz? Thanks folks ~V~ |
| ||
take off the 'global' bit. Global is for variables, not for labels. |
| ||
i know, that what i thought. i just tried the 'global' bit as a test after the initial: .mainloop goto mainloop :didnt work and i was tring to get it working, teh global isn't there now and it still wont work anyone know why? Thank |
| ||
You can't jump to a label that isnt within that function. instead use a flag variable. Like if x=1 then goto mainloop... |
| ||
that code should work.. I just tested it and it did, so I can only assume you have defined the label outside of a function and you're trying to call it from inside a function or vice-versa which you can't do. |
| ||
ah yeah, the label is inside my 'main.bb' file and the goto is in an included bb file. I dont really understand what you mean darklordz. could you post a small example or a link to clarify it plz? Thanks oh btw, is this the same for gosub, or will gosub work ok when calling function in an included bb file? And could you tell me what is the difference between calling a function (say called Render_level() for example) using just: Render_level() and using: gosub Render_level() thanks again :D |
| ||
Gosub's are in for compatiblity with older BASIC's I believe. Functions are the new way of doing things. I hear that Gosubs are actually faster at being called (which makes sense), but Functions are far more useful. You can pass parameters to a function which you can't do with a Gosub. You can return a value from a function which you can't do with a Gosub. You can use default parameters with a function which you can't do with a Gosub. Of course all of these things could be implemented using a Gosub with extra coding but isn't the point of having higher level commands to make coding easier for the programmer? But with all that said, if your 'function' doesn't require any passed parameters and doesn't need to return any values, then you might as well use a Gosub for speed. |
| ||
cheeky, thanks wolron. I dunno really what else to say, you have answered all my questions spot on :D ummmm.... thanks :D ~V~ |