PDA

View Full Version : strins() being weird


MP2
18/01/2012, 06:29 PM
Function:


stock my_ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[])
{
strins(caption, "{B800C6}", 0, 8);
strins(info, "{FFFFFF}", 0, 8);
ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
return 1;
}

#if defined _ALS_ShowPlayerDialog
#undef ShowPlayerDialog
#else
#define _ALS_ShowPlayerDialog
#endif
#define ShowPlayerDialog my_ShowPlayerDialog


Code:


new lstring[256];
format(lstring, sizeof(lstring), "This name ({FFFF82}%s{FFFFFF}) is registered. You must login to continue.\nIf this is your account, please enter the password you chose when registering below.\nIf not, please quit and reconnect with a different name.", pName[playerid]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", lstring, "Login", "Quit");


The purpose of this is to add the embedded colors to 'caption' and 'info' automatically, so they can easily be changed. I will also be adding more stuff to the my_ShowPlayerDialog function later on, so it IS needed.

Result: http://www.imagebam.com/image/0f41e8170467716

Question: Why are the buttons weird?

CmZxC
18/01/2012, 06:32 PM
nevermind

RyDeR`
18/01/2012, 06:32 PM
You can't do that as there's not enough memory allocated to insert that part into there (so you're actually inserting "illegal" memory). You will have to create a new variable and format it in there.

MP2
18/01/2012, 06:43 PM
That means I have to create 2048+64 cells. I don't really want to do that. Isn't there another way?

RyDeR`
18/01/2012, 06:51 PM
Sure there is:

#define ShowPlayerDialogEx(%0,%1,%2,%3,%4,%5,%6) \
ShowPlayerDialog((%0), (%1), (%2), "{B800C6}" %3, "{FFFFFF}" %4, (%5), (%6))

MP2
18/01/2012, 07:34 PM
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\NewServer.pwn(99) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\NewServer.pwn(99) : warning 215: expression has no effect
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\NewServer.pwn(99) : warning 215: expression has no effect
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\NewServer.pwn(99) : warning 215: expression has no effect
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\NewServer.pwn(99) : error 001: expected token: ";", but found ")"
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\NewServer.pwn(99) : error 029: invalid expression, assumed zero
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\NewServer.pwn(99) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.

Line 99:


new lstring[256];
format(lstring, sizeof(lstring), "This name ({FFFF82}%s{FFFFFF}) is registered. You must login to continue.\nIf this is your account, please enter the password you chose when registering below.\nIf not, please quit and reconnect with a different name.", pName[playerid]);
ShowPlayerDialogEx(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", lstring, "Login", "Quit");

(The ShowPlayerDialogEx function)


Can you make it replace ShowPlayerDialog, so I don't need 'Ex'?

RyDeR`
18/01/2012, 08:14 PM
Well my macro will only work for constant strings. I guess you'll have to use the string variable and format it there. Just use static string variable.

MP2
18/01/2012, 09:34 PM
But what I'm saying is, I don't want to have to create a 2048 and 64 cell string to manipulate the string in. There MUST be a way :(

RyDeR`
18/01/2012, 09:48 PM
Sorry, not that I know of. If you're using constant strings use my macro, otherwise just create a global one. 2048 isn't that bad. :p