Yup, another "tag mismatch" thread.
#1

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.

pawn Код:
stock GetGeoString(playerid, variable)
{
    new str[12];
    if(GC[playerid][variable] == 1){str = "FOUND!";}
    else {str = "Not Found";}
    return str;
}
Reply
#2

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[])
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
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.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
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:

pawn Код:
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.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
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?
Reply
#6

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:
pawn Код:
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..
Reply
#7

Quote:
Originally Posted by s0nic
Посмотреть сообщение
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:
pawn Код:
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..
Yes I understand. And I'm assuming you read the guide cover to cover if you knew how to do that lol
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)