Loading include file multiple times
Blitz3D Forums/Blitz3D Programming/Loading include file multiple times
| ||
As the title says i want to Load an include file multiple times... eg if keyhit(57) include("file.bb") Endif SO the user presses space goes through the include file returns to the main file and presses space again,which i want to runs the include again. is this possible? how? |
| ||
Why would you want to load the same file multiple times? Slightly confused by that... :o) Why not include the file at the top. The include file would only contain a function. Then call the function from within that If - Then statement. |
| ||
Why?.... longStory, i have the settings menu in a different file to the main menu...(i't seemed long before) so i prob could just make it a function in the main menu file.... but some gut feeling is saying 'i don't like that' ....yep, so that sums it up |
| ||
I hope this is a joke. |
| ||
TBH include files should only be included ONCE per source file, thats not to say you cant have an include within an include but not a good idea to keep calling em as it would make the program 'infinitely' big as each call would have to be compiled with the include data etc. |
| ||
Even if you could Include the same file several times the original question is misguided. Include essentially 'pastes' some code into the source prior to compiling. This happens before the exe is created. You can't decide whether or not to Include code based on user actions. |
| ||
Don't do that. I you need the information inside an Include file to be re-scanned at any time in the code then do something like this: ;Include your file at the top of your code this way: Goto no_scan .scan_it Include "my_file.bb" return .no_scan ;Then at any time in your code, just call a Gosub: if keyhit(28) ;Enter Gosub scan_it endif This is what I do and it works just good :) bye! Paolo. |
| ||
'Nuff said: The Include command effectively "cuts and pastes" the contents of the .bb file to be included into the current file at the point of the Include function call, temporarily, before being passed to the compiler to Execute. Note that each .bb file can only be included once. http://www.blitzbasic.com/b3ddocs/command.php?name=Include&ref=2d_a-z |
| ||
>>"Note that each .bb file can only be included once." well this isn't entirely true any longer, as far as I see. I have just included the same file twice, and the compiler didn't bother at all. |
| ||
But did it actually include the file twice? Unless this has changed since version 1.88 any extra Inludes are simply ignored. |
| ||
NO the file is not include twice. You can include the same file as many time as you want in your code, but at the compilation will only scan the first one that shows up in the code (starting from the top, of course). What I said above is useful when you have variables in your main program (local), for example arrays, and when you jump to the next level you can call a gosub to the included file so your variables can be reset or re-dimension in case of arrays... If an include only have Globals + Types + Functions, then it doesn't matter where you "include" it in the code... globals things are just detected everywhere... Paolo. |