SRL Archive - OSR Help

Includes


NKN

2012-04-23 16:03:33

Alright, alright! Last question. (I swear, I hope it is atleast)

If you're adding, and you split it up, and set global variables in the include file, will the global variables still be there to use in other files, or only that include file?

I want to seperate things, so it's like this:

RunMe–> (Get Task —-> Select Task) —> (Fight Monster —> Report to task when finished) —> Go back to Task folder, and set it to None. Ect.

Brandon

2012-04-23 16:06:31

Yeah.. Unless of course those vars are in a class.. If you have a var called X in a .Simba file.. When you include that file into your project, that var will still be there so you cannot re-declare it. Not sure if Simba has header guards so that you don't include things twice but I assume it does.

NKN

2012-04-23 18:00:47

I tried to have the second file read a variable in the first file, turns out you can't do that. xD

Brandon

2012-04-23 18:15:50

If it didn't work, your not doing it right..

See here:


Notice the duplicate identifier? That is because X is already defined as an integer or another type in Meh.Simba.. Notice how I never made a variable called Y.. But yet I can use it? Why? Because Y is defined in Meh.Simba as well.

Not only can you assign to X and Y in another file, but you can read it as well. I've done it.

Think about this scenario: We've never defined MSCX and MSX1, etc in our scripts. Well how does our scripts know what values those are? They are defined in a headerfile that is included into our scripts when we do {$I SRL/SRL.Simba}. These are global variables and constants that do not change no matter what. Re-defining them will throw an error.

NKN

2012-04-23 18:51:41

I want to add variables to the MAIN file, then have the included files read it, can I do that?

Brandon

2012-04-23 19:22:20

Lol no.. Include files aren't actually ran. Include files are known otherwise as helper files or simplification files.

We include files that hold functions or info we don't necessarily want to keep in our main file. Includes are there to be used over and over again from project to project. Think of it like a library and you just borrow books time and again. Imagine writing your own books and putting it in the library for future reference or future use. You don't exactly want to write that book again and again so you make a shelf that holds it for you. This is what an include does. It holds that data for you for future use. It's the same as functions almost. We make a function for things that we know will be ran multiple times. This way we don't keep repetitively writing the same code over and over again.

One thing you can do though is write your variables to an ini file and do whatever you want there. Not exactly sure why you want the Include files to read it variables from your main. :S You can always pass the variables to the functions in the include or You can always get scar or another instance of Simba to run your include file as long as it has a Main..

NKN

2012-04-23 19:31:14

Alright, thanks for clearing it up.

So, the file that you INCLUDED it in, can use the global variables, but the included file can't read the main. Got it, thanks. :D