Tiny C
#1

Okay, I've done a lot of programming in C/C++, so using Pawn now is a bit baffling. I have a few questions in about how things can be done. At the moment I just can't figure out how to 'pass a string' as part of an array for the MySQL plugin I'm using.

Here's my mysql_query code, which is part of my registration system:
pawn Код:
case DIALOG_Register:
        {
            if(response)
            {
                if(isnull(inputtext))
                {
                    return SendClientMessage(playerid, COLOUR_Mistake, MSG_RegHelp);
                }
                if(strlen(inputtext)<3)
                {
                    return SendClientMessage(playerid, COLOUR_Mistake, MSG_ErrorReg1);
                }

                GetPlayerName(playerid, playerInfo[playerid][pName], MAX_PLAYER_NAME);
                new query[256];

                format(query, 40+MAX_PLAYER_NAME, "SELECT name FROM users WHERE name='%s' LIMIT 1", playerInfo[playerid][pName]);
                mysql_query(query, QUERY_checkUserNotExist, {playerid, inputtext});  // <<<
                return 1;
            }
            else
            {
                ShowPlayerDialog(playerid, DIALOG_ChangeNick, 1, MSG_ChangeName, MSG_NewNickDialog, "Change", "Cancel");
            }
        }
Код:
***.pwn(601) : error 008: must be a constant expression; assumed zero
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
I assume the problem is that inputtext is a string, so it obviously can't be passed in an array as such.

Does Pawn have support for pointers and if so, how are they made? If not, how should I pass the string?
Reply
#2

My bad...
pawn Код:
mysql_query_array(query, QUERY_checkUserNotExist, {playerid, inputtext});
Still doesn't work, though. Same error.
Reply
#3

Aaany takes? I realise the problem is that I'm tryna assign vars to an array, but that still gives me no leads on how to do it properly.
Reply
#4

mysql_query(query);
Reply
#5

Haha.. clever... Yeah.

Any real answers?
Reply
#6

Hi mate I know what you mean, but you can relax there no pointers here .

What I have found is, although new var; works for integers and probably some
others without specifying type (as is fairly common in scripting), string need to be declared
like:

new string[64]; // 64 being how many characters.
Or
new string[] // No size specified, I think this is valid.

If you want to know more about PAWN specifically, their website has
a pdf document you can download, it should answer most questions where
there is confusion about differences of your usual environment and this one.
Reply
#7

Yeah, I read quite a bit of it. I'm not a visual learner though, so reading doesn't do much for me. I'm more of a hands-on kinda guy.

Without pointers, I don't think passing this much data through to a callback function is a good idea anyway. I'll try and find a better way around it, like just checking if the name exists in the DB as soon as the player connects instead of every time the player tries to register (which I probably should've done from the start).

Thanks for the help, anyways. Sucks that pointers don't exist. I noticed that "class" highlights, though. Are there classes in Pawn (even though they're probably redundant without pointers)?
Reply
#8

Yeah, I know from first look it's very different from C/C++ (I'm just going off the book in dubbing it 'Tiny C'), but I find learning things easier if I make comparisons to things I already know. The line I highlighted definitely isn't C, because I'm not trying to write C. I believe I asked no questions about the MySQL plugin, just about how passing arrays like mine to functions could work (turns out they can't, happy days).

The big thing I'm still getting used to is the lack of types
Reply
#9

What do you mean by arrays though, a character array (in other words a string) or another type of array (like an array integers or strings).

If the latter they can be passed but only to a function or class that supports them, or of course you reference a particular item of an array, as opposed to the array in it's entirety.
Reply
#10

It doesn't support enumeration arrays?

Like Delphi has record arrays (records can have vsriables of any type and then
an array declared of that type). Just curious.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)