Switch Statements And OnDialogResponse
#1

(EDIT): I've found an issue caused and linked to declaring several new variables on a same line.

The following code (for example) will compile just fine:

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 1:
        {
            new string[128];
            return 1;
        }
        case 2:
        {
            new string[128];
            return 1;
        }
    }
    return 1;
}
However when changed to...

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 1:
        {
            new DB:database, DBResult:result[2], dialog[1650], string[128], value[2][64], placeholder[3], target, time;
            return 1;
        }
        case 2:
        {
            new string[128];
            return 1;
        }
    }
    return 1;
}
The error:

Код:
error 021: symbol already defined: "string"
Will appear, all because I made several new variables along with "new string[128]".
Reply
#2

so use only one new string[128]; above switch
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
so use only one new string[128]; above switch
Yeah, probably going to do that. Found the direct issue (and updated my original post), but it seems rather odd this would be happening.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Declaring variables in switch statements is known to have issues, have you tried Zeex's compiler?
No, I have not tried any other compilers. This would be the one you are referring to, correct?
Reply
#5

Downloaded the compiler, but stuck attempting to fix the -z issue. I've tried making a shortcut to 'pawno.exe' and adding the '-z' parameter into the 'target' and 'start in' field, only to have Windows tell me the following:



I've also tried adding -z inside and outside of the quotation marks, with no luck. Am I doing something wrong? Also, do I need to launch the application with a shortcut now? Because previously, I had windows associate .pwn files with pawno.exe, so I could just click and open them instantly, but I'm assuming that isn't possible now, because of the -z parameter requirement?

(EDIT): Attempted to add "-Z" to this line:

Код:
Params= -r -w 203
In settings.ini, but I'm receiving the error from the SSCANF include now as it didn't work.

Код:
fatal error 111: user error: Please include <a_npc> or <a_samp> first.
Reply
#6

Thank you for that ******. It worked, however I found another compiler bug. I guess I'll send a message to Zeex about it. If you've got the code I posted above (second callback), it will still produce the error, and I found out that it is caused by declaring this:

Код:
value[2][64]
Having (a multi-dimensional variable I think it's called) will cause the error to happen. I suppose I could fix this by using:

Код:
value1[64], value2[64]
instead.

(EDIT): Changing:

pawn Код:
new DB:database, DBResult:result[2], dialog[1650], string[128], value[2][64], placeholder[3], target, time;
to

pawn Код:
new value[2][64], DB:database, DBResult:result[2], dialog[1650], string[128], placeholder[3], target, time;
Will fix the compiling issue.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)