Share the variable between two files? -
pellstrike - 30.01.2015
Hello. I just got stuck to this problem.
I created a gamemode which is seperated into modules(like southclaw's scavenge & survive). But command part doesn't work.
In the core file(which loaded first), I scripted like this
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new
cmd[32],
params[128];
sscanf(cmdtext, "s[32]s[128]", cmd, params);
#if defined cmd_OnPlayerCommandText
return cmd_OnPlayerCommandText(playerid, cmdtext[]);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerCommandText
#undef OnPlayerCommandText
#else
#define _ALS_OnPlayerCommandText
#endif
#define OnPlayerCommandText cmd_OnPlayerCommandText
#if defined cmd_OnPlayerCommandText
forward cmd_OnPlayerCommandText(playerid, cmdtext[]);
#endif
and second file, which loaded later, is scripted like this
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmd, "/ahelp", true))
{
return 1;
}
#if defined admin_OnPlayerCommandText
return admin_OnPlayerCommandText(playerid, cmdtext);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerCommandText
#undef OnPlayerCommandText
#else
#define _ALS_OnPlayerCommandText
#endif
#define OnPlayerCommandText admin_OnPlayerCommandText
#if defined admin_OnPlayerCommandText
forward admin_OnPlayerCommandText(playerid, cmdtext[]);
#endif
and the error comes out
Код:
error 017: undefined symbol "cmd"
I understand this error, but I can't figure out how to solve this. What I want is to use cmd variable in first file in second file. Is this possible

Thanks
Re: Share the variable between two files? -
pellstrike - 30.01.2015
Thanks, but I have to use strcmp. because I'm not english user(Korean), I can't create command such as CMD: something. When I trying to create a command with y_commands or something like that, I got errors.
As far as I know there is no solution for this problem. So I have to use this.
Re: Share the variable between two files? -
DRIFT_HUNTER - 30.01.2015
Like ****** said, use y_commands or zcmd (They use same principle)
Anyway if you still want to use strcmp, and i dont see a reason for that but what a hell...you asked for help her you go...
Second file if(!strcmp(cmd, "/ahelp", true))
change cmd to cmdtext
[EDIT]Oh wait, i just noticed that i misunderstood you...
Well in that case you will eather call custom function yourself or a simple solution y_commands/zcmd
Re: Share the variable between two files? -
pellstrike - 30.01.2015
Interesting, Thanks ******. I'll give it a try. But there are many commands on my mode. Changing every command with this method is too heavy work for me
Anyway, I just created this script below. Is there any problem? I run this script and it works fine, but I think this is not Ideal way to do this.
First file.
Код:
new
core_cmd[32],
core_params[128],
core_targeitd = INVALID_PLAYER_ID;
public OnPlayerCommandText(playerid, cmdtext[])
{
#define cmd core_cmd
#define params core_params
#define targetid core_targetid
sscanf(cmdtext, "s[32]s[128]", cmd, params);
#if defined core_OnPlayerCommandText
return core_OnPlayerCommandText(playerid, cmdtext[]);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerCommandText
#undef OnPlayerCommandText
#else
#define _ALS_OnPlayerCommandText
#endif
#define OnPlayerCommandText core_OnPlayerCommandText
#if defined core_OnPlayerCommandText
forward core_OnPlayerCommandText(playerid, cmdtext[]);
#endif
There are three variables and they are global. and in OnPlayerCommandText(hooked), I changed their name using macro.
So, second file:
Код:
#include <YSI\y_hooks>
hook OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmd, "/ahelp", true))
{
print("abc");
return 1;
}
return 0;
}
Will this work properly without any critical problem?
Re: Share the variable between two files? -
pellstrike - 30.01.2015
Ah, you know, I've already created many commands and they use variable which is named 'cmd'. and cmd is more friendly than core_cmd.... for me

.
again, Thanks, ******!
Re: Share the variable between two files? -
CalvinC - 30.01.2015
Improving your code should always be important to do, in several aspects.
You can use CTRL+H to replace pieces of your code with something else.