PAWN-knowledge needed: Is there a way to "forward" variables?
#1

Hi
As I am currently developing a big modular project I encountered a problem. The situation is the following:

I got a load of includes that all for themselves provide specific features. Some of the includes depend on the functions or variables of other includes. Normally this can be solved by loading the depending include after the needed include, but now I ran into an ugly circle, so include A needs include B, and include B needs include A, so this cant be solved by including A before B or the other way round.

As we all know (at least I hope so), for functions there is the forward keyword that makes function "accessable from any position", but this just works for functions, not for variables.

I already thought about creating headerfiles for each include that just contain all the variables, and are loaded at the very beginning. This is a common solution, as it is popular in other languages, but I wouldnt like to do it, if there was another solution, as I use the standard PAWNO editor, and already got enough windows opened, and I really wouldnt like to double these windows


So again my question in short: Is there a way to "forward" variables to make them useable before they are created in the script?
Im not asking questions here often, but reading and searching didnt help, so I doubt there is a way, but asking cant harm. I would really appreciate if anyone had an answer for this problem.
Reply
#2

Cant you just include the includes into each other? If they are variables that can be used as Pvar's, Pvars are global across all scripts as well.
Reply
#3

You know that CallRemoteFunction returns the return value of the function. You can make a use of that to call some variables. Example:
pawn Код:
forward myVar(index); public myVar(index)
{
    switch(index)
    {
        case 0: return variable1;
        case 1: return variable2;
    }
    return -1;
}
pawn Код:
CallRemoteFunction("myVar", "i", index);
You can maybe change it to a string and than use strcmp instead of index to make it not confusing.

Other option is to use GVar Plugin which is very fast when it comes on performance.
Reply
#4

Thanks for your answers, guys!
I also dont think pvars are good, as they would slow down everything a lot, and remotefunctions also would be much slower than normal variables, and i got lots of variables, so this would probably make the script unuseable.

Including the includes after defining the variables sounds good, I already do this in the main gamemode, dont know why I didnt thought about this earlier. It might just get a bit messy if there are tons of includes depending on each other and other includes, but for my needs this should do it perfectly and Im already working to reduce cross references as good as possible, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)