Variables mixing.
#1

Hello everybody, I have a question.. So, Im creating a trucking gamemode and I am creating every system in other .pwn file (I am using y_hooks to hook callbacks).

The systems:

pawn Код:
#include "System/settings.pwn"
#include "System/players.pwn"
#include "System/classes.pwn"
Everything is good with y_hooks, but for example: in classes.pwn there's variable iClass. And I am using that variable in players.pwn, but I get error that symbol iClass is undefined.

If I do

pawn Код:
#include "System/settings.pwn"
#include "System/classes.pwn"
#include "System/players.pwn"
Then for example in players.pwn there's variables szIP, szName. And I am using those variables in classes.pwn, so I get error in classes.pwn that symbols szIP, szName are undefined.

Any solutions?
Reply
#2

Anyone? Please..
Reply
#3

Create the variables before you include the required files?
Reply
#4

EDIT: nvm.
Reply
#5

funky >> I think you didnt got the point. Read the thread again.
Reply
#6

Quote:
Originally Posted by BaubaS
Посмотреть сообщение
funky >> I think you didnt got the point. Read the thread again.
I did get the point.

I mean, create the variable before including the files.

pawn Код:
new
    SuperVar, BaubaS
;
#include <superinclude>
#include <BaubaSinclude>
Let's pretend I simply created "SuperVar" in "BaubaSinclude", "superinclude" wouldn't have access to SuperVar because it's declared afterwards (not strictly true in all circumstances, but is in this case).
Reply
#7

Declare all your global variables as static in every file - unless you explicitly need to access that variable in another file - and your problems will be solved.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Declare all your global variables as static in every file - unless you explicitly need to access that variable in another file - and your problems will be solved.
Thanks for helping, but same..

For example, in players.pwn I've changed

pawn Код:
new
    szName[MAX_PLAYERS][MAX_PLAYER_NAME],
    szIP[MAX_PLAYERS][16];
to

pawn Код:
static
    szName[MAX_PLAYERS][MAX_PLAYER_NAME],
    szIP[MAX_PLAYERS][16];
.

I've saved the file, and when I am compiling the main .pwn file, it gives

pawn Код:
System/classes.pwn(131) : error 017: undefined symbol "szName"
System/classes.pwn(131) : error 029: invalid expression, assumed zero
System/classes.pwn(131) : error 029: invalid expression, assumed zero
System/classes.pwn(131) : fatal error 107: too many error messages on one line
Line 131:
pawn Код:
format(szMembers, 810, "%s{33AA33}%d. {FF0000}%s\n", szMembers, ClassMembers, GetPlayerNameEx(i));
Defines:

pawn Код:
#define GetPlayerNameEx(%0)  (szName[%0])
#define GetPlayerIpEx(%0)    (szIP[%0])
Reply
#9

Quote:
Originally Posted by BaubaS
Посмотреть сообщение
Thanks for helping, but same..

For example, in players.pwn I've changed

pawn Код:
new
    szName[MAX_PLAYERS][MAX_PLAYER_NAME],
    szIP[MAX_PLAYERS][16];
to

pawn Код:
static
    szName[MAX_PLAYERS][MAX_PLAYER_NAME],
    szIP[MAX_PLAYERS][16];
.

I've saved the file, and when I am compiling the main .pwn file, it gives

pawn Код:
System/classes.pwn(131) : error 017: undefined symbol "szName"
System/classes.pwn(131) : error 029: invalid expression, assumed zero
System/classes.pwn(131) : error 029: invalid expression, assumed zero
System/classes.pwn(131) : fatal error 107: too many error messages on one line
Line 131:
pawn Код:
format(szMembers, 810, "%s{33AA33}%d. {FF0000}%s\n", szMembers, ClassMembers, GetPlayerNameEx(i));
Defines:

pawn Код:
#define GetPlayerNameEx(%0)  (szName[%0])
#define GetPlayerIpEx(%0)    (szIP[%0])
Ignoring my post will get you nowhere, trust me. I have practically the same setup as you're intending to have.
Reply
#10

Quote:
Originally Posted by funky1234
Посмотреть сообщение
Ignoring my post will get you nowhere, trust me. I have practically the same setup as you're intending to have.
Nah, I am not ignoring your posts, but if I will use your method, there will be no point to hook tha systems, because global variables will be in the main file, not in the system file. Im tryin' to get the best. :3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)