PDA

View Full Version : Yup, another "tag mismatch" thread.


Aerotactics
05/06/2014, 05:42 AM
Brief: "variable" is a variable the player can input to the stock, getting a tag mismatch on the line with "variable." If you could explain why this doesn't work, that'd be great.


stock GetGeoString(playerid, variable)
{
new str[12];
if(GC[playerid][variable] == 1){str = "FOUND!";}
else {str = "Not Found";}
return str;
}

BroZeus
05/06/2014, 05:50 AM
i dont understand what u are trying to say
but if u are saying that variable is a string then this would be stock line --
stock GetGeoString(playerid, variable[])

Aerotactics
05/06/2014, 06:15 AM
i dont understand what u are trying to say
but if u are saying that variable is a string then this would be stock line --
stock GetGeoString(playerid, variable[])

That's it, thanks.

Aerotactics
05/06/2014, 09:35 AM
That's not it at all! You can't use a string to index an array. The problem is probably with the declaration of "GC", which you didn't post.

You're right, here's my code:


enum geos
{
easy1,
easy2,
easy3,
med1,
med2,
med3,
hard1,
hard2,
hard3,
exp1
}
new GC[MAX_PLAYERS][geos];

stock GetGeoString(playerid, variable[])
{
new str[12];
if(GC[playerid][variable] == 1){str = "FOUND!";}
else {str = "Not Found";}
return str;
}


And the output errors:

C:\Users\Aerotactics\Desktop\SAMP testing\filterscripts\geo.pwn(58) : error 035: argument type mismatch (argument 2)
C:\Users\Aerotactics\Desktop\SAMP testing\filterscripts\geo.pwn(66) : error 033: array must be indexed (variable "variable")

What I'm trying to do is what it looks like, simply getting a string based on a variable. That variable is in an enumerator, however. By creating a stock, I was intending on making the script more efficient.

Aerotactics
05/06/2014, 11:03 AM
Yeah, that's not even close to how enums work. The fact that they are named constants in source code is purely for programmer reference, those "strings" are lost at compile time. I suggest you re-read the section of pawn-lang.pdf on enums.

Will do, thanks ******.

EDIT: I must point out I never read the pdf before, and that all my knowledge was purely from trial/error, reading other scripts, and checking the wikis often. Does the guide explain every aspect of pawn?

s0nic
05/06/2014, 09:20 PM
Yes I would say the guide explains pretty much every aspect.
And even though I didn't quite understand what you were fully trying to achieve with that function..
If you do ever try to check a variables data by passing it through a function like that you can handle it like this:

stock GetGeoString(playerid, variable)
{
new str[12];
if(GC[playerid][geos:variable] == 1){str = "FOUND!";}
else {str = "Not Found";}
return str;
}

As you can see you need to point it to the enum that the variable is using.
The names within a enum are basically placeholders, each correspond to a number
Ex:
easy1, = 0
easy2, = 1
easy3, = 2
So when you are trying to do GetGeoString(playerid, easy1) its going to read like GetGeoString(0, 0) which is why GC[playerid][variable] wouldn't have worked as it would be expecting a placeholder name but a integer was being passed through and if you point to the enum it then you shall be good to go.

Hopefully you can understand what I was trying to explain.. :cool:

Aerotactics
06/06/2014, 02:27 AM
Yes I would say the guide explains pretty much every aspect.
And even though I didn't quite understand what you were fully trying to achieve with that function..
If you do ever try to check a variables data by passing it through a function like that you can handle it like this:

stock GetGeoString(playerid, variable)
{
new str[12];
if(GC[playerid][geos:variable] == 1){str = "FOUND!";}
else {str = "Not Found";}
return str;
}

As you can see you need to point it to the enum that the variable is using.
The names within a enum are basically placeholders, each correspond to a number
Ex:
easy1, = 0
easy2, = 1
easy3, = 2
So when you are trying to do GetGeoString(playerid, easy1) its going to read like GetGeoString(0, 0) which is why GC[playerid][variable] wouldn't have worked as it would be expecting a placeholder name but a integer was being passed through and if you point to the enum it then you shall be good to go.

Hopefully you can understand what I was trying to explain.. :cool:

Yes I understand. And I'm assuming you read the guide cover to cover if you knew how to do that lol