Page 1 of 2
combining cvar strings
Posted: Thu Jun 03, 2004 10:31 pm
by oddball
i was wondering if it's possible to combine 2 vars(both strings) to one var/string.
What i want:
as example "
local.newstring = local.str[1] + local.str[3]
or
local.newstring = local.str1 + local.str[3]
i always comes up with the error :
Script Error: binary '+' applied to incompatible types 'char' and 'char'
is there a command to make it a character? like int for integer ?
or maybe another good way to do it?
thanks in advance
Posted: Thu Jun 03, 2004 10:35 pm
by blue60007
Well the intilization for a character is usually 'char' I don't think you can add strings via operators.

Don't know...

Posted: Fri Jun 04, 2004 1:19 am
by oddball
i tried char(local.str) but the engine doesn't understand it
comes up with an error.
so i don't if there is a command like int for characters as char isn't working.
Posted: Fri Jun 04, 2004 3:01 am
by bdbodger
I think strings are arrays of length 1 or something like that so maybe try
for(local.i = 1;local.i <= local.string1.size;local.i++)
{
local.newstring[local.i] = local.string1[local.i]
}
local.b = local.newstring.size+1
for(local.i = 1;local.i <= local.sting2.size;local.i++)
{
local.newstring[local.b] = local.string2[local.i]
local.b ++
}
predefinded
Posted: Fri Jun 04, 2004 3:42 am
by tltrude
To combine strings it would look like this, I think.
local.str1 = "Eat"
local.str2 = "at"
local.str3 = "Joe's"
local.newstring = ((local.str1) + " " + (local.str2) + " " + (local.str3) + "!")
iprintln (local.newstring) // Eat at Joe's!
There is probably a command for adding a space, but I only know the one for new line "\n"--must be in quotes. So, I added the spaces with " ".
Posted: Fri Jun 04, 2004 9:05 am
by jv_map
That's right Tom that should work perfectly, you can even do it without all the parens (makes it more readable):
local.newstring = local.str1 + " " + local.str2 + " " + local.str3
iprintln local.newstring
The thing what you tried Oddball doesn't work because you're only accessing one character of the string, so your adding two chars (which should still result in 1 char) instead of two strings...
Posted: Fri Jun 04, 2004 10:27 am
by bdbodger
well there ya go
and
local.string = (getcvar(thing1)) + ( getcvar(thing2))
too I guess
Posted: Fri Jun 04, 2004 12:01 pm
by oddball
I know howto combine the normal strings/cvars.
The proble in this case is, i want to split up the maplist in an array.
i want to split it up on every space so i was thinking to read every character in the maplist and put it in the new cvar array until a space is detected.
so obj/obj_team1 obj/obj_team2 obj/obj_team3 obj/obj_team4
would be:
local.maparray[0] >>> obj/obj_team1
local.maparray[1] >>> obj/obj_team2
local.maparray[2] >>> obj/obj_team3
local.maparray[3] >>> obj/obj_team4
maybe you have a more simple idea?
Posted: Fri Jun 04, 2004 2:04 pm
by jv_map
Oooh you should have asked that instead
Anyway try this:
Code: Select all
local.maplist = getcvar sv_maplist
local.j = 1
local.mapname[1] = ""
for(local.i = 0; local.i < local.maplist.size; local.i++)
{
local.char = local.maplist[local.i]
if(local.char == " ")
{
local.j++
local.mapname[local.j] = "" // create a string
}
else
local.mapname[local.j] += local.char
}
Posted: Fri Jun 04, 2004 3:22 pm
by blue60007
\n = newline
\t = tab
\0 = null
\\ = \
I think a space could be add like: " "

Posted: Fri Jun 04, 2004 3:30 pm
by oddball
thanks JV_map,
that was what i needed.
is local.char just another string or does char atualy mean something the engine understands as character?
Script Files.txt
Posted: Fri Jun 04, 2004 8:52 pm
by tltrude
I found this in docs/Script Files.txt at the bottom of the page.
----------------------------------------------------------------
Accessing characters of a string
================================
Characters of a string are accessed by the [] array operator. Indexing starts at 0. For example, "abc"[2] evaluates to the string "c". There is no character type, so characters are just strings of length 1.
----------------------------------------------------------------
Also, thanks for the string printing commands, blue60007! Oddball - remember, they must be in quotes to use them.
Posted: Fri Jun 04, 2004 8:57 pm
by jv_map
Well seeing the error in oddballs first post it seems like there actually is a char type:
Script Error: binary '+' applied to incompatible types 'char' and 'char'
Posted: Sat Jun 05, 2004 3:36 pm
by oddball
ok, here's the result for the code.
I made a script that warns you for custom maps.
feel free to use it on your servers when needed.
Code: Select all
// Custom map warning version 1.00
// This mod is created by [VS-UK]Lt.OddBall[BnHQ]
// The mod tells players what map comes next and warns them there's a custom map comming up.
// it also warns that if they don't have it, the server will kick them/
// the bot gives info where to get the maps
Start:
thread SendWarning
end
SendWarning:
wait 5
local.maplist = getcvar sv_maplist
local.j = 1
local.mapname[1] = ""
for(local.i = 0; local.i < local.maplist.size; local.i++)
{
local.char = local.maplist[local.i]
if(local.char == " ")
{
local.j++
local.mapname[local.j] = "" // create a string
}
else
local.mapname[local.j] += local.char
}
while(1)
{
level.currentmap = getcvar mapname
for(local.h = 1; local.h < local.j ; local.h++)
{
//println "mapname = " local.mapname[local.h]
if (level.currentmap == local.mapname[local.h])
{
level.CurrMapNumber = int(local.h)
//println "FOUND!!!!!"
//println "mapnumber + 1= " (level.CurrMapNumber + 1)
//println "nextmapname is " local.mapname[level.CurrMapNumber + 1]
if ((level.CurrMapNumber + 1) <= (local.j - 1))
{
if ((local.mapname[level.CurrMapNumber + 1] == "obj/obj_team1") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/obj_team2") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/obj_team3") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/obj_team4") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm1") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm2") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm3") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm4") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm5") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm6") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/mohdm7") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Druckkammern_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Flughafen_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Ardennes_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "obj/MP_Berlin_TOW") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Bahnhof_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Bazaar_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Brest_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Holland_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Stadt_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Gewitter_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Unterseite_DM") ||
(local.mapname[level.CurrMapNumber + 1] == "dm/MP_Verschneit_DM"))
{
iprintln "The current map is " level.currentmap
iprintln "The next map is " local.mapname[level.CurrMapNumber + 1]
}
else
{
iprintln "Next map is " local.mapname[level.CurrMapNumber + 1]
iprintln "this is a custom map, if you don't have it, the server will kick you"
iprintln "you can download the map at http://www.vs-uk.net"
}
}
else
{
if ((local.mapname[1] == "obj/obj_team1") ||
(local.mapname[1] == "obj/obj_team2") ||
(local.mapname[1] == "obj/obj_team3") ||
(local.mapname[1] == "obj/obj_team4") ||
(local.mapname[1] == "dm/mohdm1") ||
(local.mapname[1] == "dm/mohdm2") ||
(local.mapname[1] == "dm/mohdm3") ||
(local.mapname[1] == "dm/mohdm4") ||
(local.mapname[1] == "dm/mohdm5") ||
(local.mapname[1] == "dm/mohdm6") ||
(local.mapname[1] == "dm/mohdm7") ||
(local.mapname[1] == "obj/MP_Druckkammern_TOW") ||
(local.mapname[1] == "obj/MP_Flughafen_TOW") ||
(local.mapname[1] == "obj/MP_Ardennes_TOW") ||
(local.mapname[1] == "obj/MP_Berlin_TOW") ||
(local.mapname[1] == "dm/MP_Bahnhof_DM") ||
(local.mapname[1] == "dm/MP_Bazaar_DM") ||
(local.mapname[1] == "dm/MP_Brest_DM") ||
(local.mapname[1] == "dm/MP_Holland_DM") ||
(local.mapname[1] == "dm/MP_Stadt_DM") ||
(local.mapname[1] == "dm/MP_Gewitter_DM") ||
(local.mapname[1] == "dm/MP_Unterseite_DM") ||
(local.mapname[1] == "dm/MP_Verschneit_DM"))
{
iprintln "The current map is " level.currentmap
iprintln "The next map is " local.mapname[1]
}
else
{
iprintln "Next map is " local.mapname[1]
iprintln "this is a custom map, if you don't have it, the server will kick you"
iprintln "you can download the map at http://www.vs-uk.net"
}
}
}
}
wait 60
}
end
Posted: Sun Jun 06, 2004 4:03 am
by blue60007
Oooh very nice!

That'll help and minimize errors from clients not having a custom map...