String Definitions
#1

I want to keep my script easily customizable, so localization is a smart thing to add imo. Just wondering if it is possible to have a string definition that can have placeholders in it?

Код:
#define stringWelcome "Welcome to %s server, %s. Please enjoy your stay."
#define serverName "The Fun Zone"
...

OnPlayerConnect(playerid){
    new string[128], playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    format(string, stringWelcome, serverName, playerName);
    SendClientMessage(playerid, 0xFFFFFFFF, string);
}
Something like this would be very useful for translating scripts into different languages or just changing the messages in general.
Reply
#2

Well that is a very nice idea. Why don't you try and find out?

EDIT: I tried it out and gives a tag mismatch error in the line
Код:
format(string, stringWelcome, serverName, playerName);
I don't see a possibilty.
Reply
#3

Well I wasn't expecting that code to work lol :P

But yeah, I was just trying to get my idea across. I think it is a great idea too, but I think we may need some big shot like ****** for this one.
Reply
#4

bump
Reply
#5

Код:
format(string, 128, stringWelcome, serverName, playerName);
Should work. I used this on my script.

edit: mine is more like

Код:
format(string, 128, "%s", stringWelcome, serverName, playerName);
Reply
#6

Obiously that won't work.

I'd try it like this:

pawn Код:
format(string,sizeof(string)',"Welcome to %s server, %s. Please enjoy your stay.",servername,playerName);
Reply
#7

Quote:
Originally Posted by Hiddos
Obiously that won't work.

I'd try it like this:

pawn Код:
format(string,sizeof(string)',"Welcome to %s server, %s. Please enjoy your stay.",servername,playerName);
Well your missing the point then Hiddos. ledzep wants that the line "Welcome to %s" be defined as

Код:
#define Welcome Welcome to %s.
Reply
#8

pawn Код:
new string[60];
format(string, sizeof(string), welcomeString, serverName, player_name);
Need to define player_name by getting the players name.
Reply
#9

I'm quite unsure if that's possible. Im at school ATM, so I can't check. But I think you're already putting in a pre-defined string that way.

Last try:

pawn Код:
#define stringWelcome "Welcome to"
#define serverName "The Fun Zone"
#define stringWelcomemid "server,"
#define stringWelcomeend "Please enjoy your stay."
...

OnPlayerConnect(playerid){
    new string[128], playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    format(string, "%s % %s %s, %s",stringWelcome,serverName,stringWelcomemid,playerName,stringWelcomeend);
    SendClientMessage(playerid, 0xFFFFFFFF, string);
}
Didn't try anything, but I think you know what I mean.
Reply
#10

Take an example, like I use this for files:
pawn Код:
#define USER_FILE "/Users/%s.ini"
// somewhere else
new file[40];
format(file, sizeof(file), USER_FILE, name);
That works, I know for a fact, I use it every day pretty much. Now if you look, the other example I posted above is done the same exact way.

Err, never mind, I think I just figured out what you meant. Putting a pre-defined string into another. Not sure, but I'm pretty confident that will work. I'll throw it into the compiler when I get upstairs (I hate stairs)

EDIT: I just tested with this code; compiled with no errors/warnings:
pawn Код:
#include <a_samp>

#define welcomeString  "Welcome to %s, %s. Please enjoy your stay"
#define serverName   "The Fun Server"

public OnPlayerConnect(playerid)
{
    new str[50], player_name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, player_name, MAX_PLAYER_NAME);
    format(str, sizeof(str), welcomeString, serverName, player_name);
    print(str);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)