concatenate text
Moderator: Graphics Moderators
concatenate text
Hello,
Can anyone help me to concatenate 2 or 3 text strings in nml?
I've try with switches and load variables:
switch (FEAT_ROADVEHS, SELF, switch_Geo, [
STORE_TEMP(string(STR_GEO) ,0),
STORE_TEMP(string(STR_GEO1) ,1),
])
{
return LOAD_TEMP(0)+LOAD_TEMP(1);
}
I'm trying to show multiple strings in the purchase menu, but those strings are store separately in the lang file.
Thanks
Can anyone help me to concatenate 2 or 3 text strings in nml?
I've try with switches and load variables:
switch (FEAT_ROADVEHS, SELF, switch_Geo, [
STORE_TEMP(string(STR_GEO) ,0),
STORE_TEMP(string(STR_GEO1) ,1),
])
{
return LOAD_TEMP(0)+LOAD_TEMP(1);
}
I'm trying to show multiple strings in the purchase menu, but those strings are store separately in the lang file.
Thanks
Re: concatenate text
1. First you need to add {STRING} parameters to the strings, where another string should be inserted.
1a. Either you add it at then end of the first string:
1b. Or you add a generic string to concatenate two strings:
2. Second you need to decide, whether you want to concatenate the strings at compile time, or at run time.
2a. Concatenate at compile time:
This will occupy another string ID for the concatenated text. So if you have many different combinations of concatenations of the same strings, you may run out of string IDs.
For option (1a):
For option (1b):
2b. Concatenate at run time:
For this you need to put the strings to insert onto the text stack (temp storage 0x100..0x10F).
For option (1a):
For option (1b):
1a. Either you add it at then end of the first string:
Code: Select all
STR_GEO :...your text....{STRING}
Code: Select all
STR_CONCAT :{STRING}{STRING}
2. Second you need to decide, whether you want to concatenate the strings at compile time, or at run time.
2a. Concatenate at compile time:
This will occupy another string ID for the concatenated text. So if you have many different combinations of concatenations of the same strings, you may run out of string IDs.
For option (1a):
Code: Select all
return string(STR_GEO, string(STR_GEO1))
Code: Select all
return string(STR_CONCAT, string(STR_GEO), string(STR_GEO1))
For this you need to put the strings to insert onto the text stack (temp storage 0x100..0x10F).
For option (1a):
Code: Select all
return [STORE_TEMP(string(STR_GEO1), 0x100), string(STR_GEO) - 0xD000];
Code: Select all
return [STORE_TEMP(string(STR_GEO) | string(STR_GEO1) << 16, 0x100), string(STR_CONCAT) - 0xD000];
Last edited by frosch on 05 Apr 2025 18:29, edited 1 time in total.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Re: concatenate text
Thank you for your answer.
But the command return string(str1,str2) is not compiling. I've also try return[(string(str1),string(str2)] this one compile but give error when try to execute.
Any ideea?
But the command return string(str1,str2) is not compiling. I've also try return[(string(str1),string(str2)] this one compile but give error when try to execute.
Any ideea?
Re: concatenate text
Manage to concatenate 2 strings, but not 3.
return STORE_TEMP(string(str1) | string(str2)《16,256)
and in lang file refer to {STRING}{STRING}
But cound not concatenate 3 strings, try even with LOAD_TEMP: store first 2 string in a temp var, then loaded and conatenate the 3rd. But only 1st and 3rd where shown.
return STORE_TEMP(string(str1) | string(str2)《16,256)
and in lang file refer to {STRING}{STRING}
But cound not concatenate 3 strings, try even with LOAD_TEMP: store first 2 string in a temp var, then loaded and conatenate the 3rd. But only 1st and 3rd where shown.
Re: concatenate text
I edited my original post to fix the "compile time" case.
You cannot load/store a string with LOAD_TEMP/STORE_TEMP. You can only load/store string IDs. And adding string IDs makes no sense.
Each text stack storage can only hold two parameters. So to concat 3 strings at runtime, you need two storages.
For option (1b):
You cannot load/store a string with LOAD_TEMP/STORE_TEMP. You can only load/store string IDs. And adding string IDs makes no sense.
Each text stack storage can only hold two parameters. So to concat 3 strings at runtime, you need two storages.
For option (1b):
Code: Select all
STR_CONCAT3 :{STRING}{STRING}{STRING}
Code: Select all
return [
STORE_TEMP(string(STR_GEO1) | string(STR_GEO2) << 16, 0x100), // first two parameters
STORE_TEMP(string(STR_GEO3), 0x101), // third parameter
string(STR_CONCAT3) - 0xD000
];
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Who is online
Users browsing this forum: No registered users and 3 guests