Is this shortcut possible
#1

So I'm trying to create a shortcut for a long code so that I won't keep copying and pasting everything.

PHP код:
stock UpdateAttribute(playeridtd, var)
{
    if(
PlayerInfo[playerid][var] == 1//131
    
{
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O "COL_WHITE"O O O O O O O O O"); //133
    
}
    else if(
PlayerInfo[playerid][var] == 2)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O "COL_WHITE"O O O O O O O O");
    }
    else if(
PlayerInfo[playerid][var] == 3)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O "COL_WHITE"O O O O O O O");
    }
    else if(
PlayerInfo[playerid][var] == 4)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O O "COL_WHITE"O O O O O O");
    }
    else if(
PlayerInfo[playerid][var] == 5)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O O O "COL_WHITE"O O O O O");
    }
    else if(
PlayerInfo[playerid][var] == 6)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O O O O "COL_WHITE"O O O O");
    }
    else if(
PlayerInfo[playerid][var] == 7)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O O O O O "COL_WHITE"O O O");
    }
    else if(
PlayerInfo[playerid][var] == 8)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O O O O O O "COL_WHITE"O O");
    }
    else if(
PlayerInfo[playerid][var] == 9)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O O O O O O O "COL_WHITE"O");
    }
    else if(
PlayerInfo[playerid][var] == 10)
    {
        
PlayerTextDrawSetString(playeridtd[playerid], ""COL_GREEN"O O O O O O O O O O");
    }
    return 
1;

Although this gives errors such as
Код:
(131) : warning 213: tag mismatch
(133) : error 028: invalid subscript (not an array or too many subscripts): "td"
(133) : warning 215: expression has no effect
(133) : error 001: expected token: ";", but found "]"
(133) : error 029: invalid expression, assumed zero
(133) : fatal error 107: too many error messages on one line
What I'm trying to make

Код:
UpdateAttribute(playerid, AttributePTD1, Potency);
Reply
#2

You can't do what you're trying to do.

You'll need to find your way with #define
Reply
#3

Quote:
Originally Posted by Kaperstone
Посмотреть сообщение
You can't do what you're trying to do.

You'll need to find your way with #define
Right. So, uh, how do we do that?
Reply
#4

pawn Код:
#define UpdateAttribute(%0,%1,%2); \
new str[36];strcat(str,""COL_GREEN"");for(new x=0;x<10;x++){if(x==PlayerInfo[%0][%1]){strcat(str,""COL_WHITE"");}strcat(str,"O");if(x<10){strcat(str," ");}}PlayerTextDrawSetString(%0, %2[%0], str);
EDIT: Forgot that in define, on the first parameter you don't add spaces.
EDIT2: leftout playerid, and I separated the string from the array, just in case.
Reply
#5

Thanks for the quick response! Although there were still some errors that showed up

Код:
barp.pwn(984) : warning 236: unknown parameter in substitution (incorrect #define pattern)
(984) : warning 236: unknown parameter in substitution (incorrect #define pattern)
(984) : warning 236: unknown parameter in substitution (incorrect #define pattern)
(984) : warning 236: unknown parameter in substitution (incorrect #define pattern)
(984) : error 029: invalid expression, assumed zero
(984) : warning 215: expression has no effect
(984) : error 029: invalid expression, assumed zero
(984) : warning 215: expression has no effect
(984) : error 001: expected token: ";", but found ")"
(984) : fatal error 107: too many error messages on one line
Line
PHP код:
UpdateAttribute(playeridAttributePTD1Potency); 
Reply
#6

I by mistake, added spaces to the first parameter of the code.
Reply
#7

Right, didn't notice that too. Ayt, everything's finished. There are some indent warnings tho on the same line, even if it's properly indented. But that's just indention. Thanks!

PS: Just if you know how to solve this one

PHP код:
public OnPlayerClickTextDraw(playeridText:clickedid)
{
    if(
clickedid == AttributeTD17)
    {
        if(
attselect[playerid] == 1)
        {
            if(
PlayerInfo[playerid][Potency] < 11)
            {
                
PlayerInfo[playerid][Potency] += 1;
                
SendClientMessage(playerid, -1""COL_GREEN"[ATTRIBUTES:]"COL_WHITE" You have upgraded your Potency attribute and gained an additional damage in Unarmed Strength.");
                
UpdateAttribute(playeridPotencyAttributePTD1); //two indent warnings here
            
}
            else return 
ERROR(playerid"You already have the maximum upgrade of this Attribute");
        }
        return 
1;
    }
    return 
0;

Reply
#8

Either space/tab or its because of the define, possibly because of the break line ? ( \ )
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)