SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/06/2014, 12:02 AM   #1
DrakeX
Banned
 
Join Date: Dec 2011
Posts: 73
Reputation: 49
Post Switch Statements And Variables (Error Produced)

(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 Code:
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 Code:
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:

Code:
error 021: symbol already defined: "string"
Will appear, all because I made several new variables along with "new string[128]".
DrakeX is offline   Reply With Quote
Old 13/06/2014, 12:14 AM   #2
Jefff
Banned
 
Join Date: Dec 2007
Posts: 2,594
Reputation: 326
Default Re: Switch Statements And OnDialogResponse

so use only one new string[128]; above switch
Jefff is offline   Reply With Quote
Old 13/06/2014, 12:16 AM   #3
DrakeX
Banned
 
Join Date: Dec 2011
Posts: 73
Reputation: 49
Default Re: Switch Statements And OnDialogResponse

Quote:
Originally Posted by Jefff View Post
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.
DrakeX is offline   Reply With Quote
Old 13/06/2014, 01:32 AM   #4
DrakeX
Banned
 
Join Date: Dec 2011
Posts: 73
Reputation: 49
Default Re: Switch Statements And OnDialogResponse

Quote:
Originally Posted by ****** View Post
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?
DrakeX is offline   Reply With Quote
Old 14/06/2014, 08:47 PM   #5
DrakeX
Banned
 
Join Date: Dec 2011
Posts: 73
Reputation: 49
Default Re: Switch Statements And OnDialogResponse

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:

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

Code:
fatal error 111: user error: Please include <a_npc> or <a_samp> first.

Last edited by DrakeX; 15/06/2014 at 06:15 AM.
DrakeX is offline   Reply With Quote
Old 15/06/2014, 05:46 PM   #6
DrakeX
Banned
 
Join Date: Dec 2011
Posts: 73
Reputation: 49
Default Re: Switch Statements And OnDialogResponse

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:

Code:
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:

Code:
value1[64], value2[64]
instead.

(EDIT): Changing:

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

to

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

Will fix the compiling issue.

Last edited by DrakeX; 16/06/2014 at 05:29 AM.
DrakeX is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ajuda] Switch ou if ? (OnDialogResponse) Juniiro3 PortuguÍs/Portuguese 23 11/10/2013 10:12 AM
How do you use 2 if statements? muhib777 Scripting Help 5 05/05/2012 07:14 PM
If Statements x && ipsBruno Scripting Help 7 01/05/2012 08:18 PM
switch versus if-statements? LarzI Help Archive 4 07/10/2010 02:11 PM
If statements help Memoryz Help Archive 2 01/05/2010 01:47 AM


All times are GMT. The time now is 06:48 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.