combining cvar strings

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
oddball
Corporal
Posts: 44
Joined: Tue May 27, 2003 3:49 pm
Contact:

combining cvar strings

Post 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
[VS-UK]Maj.OddBall[BnHQ]
blue60007
General
Posts: 1247
Joined: Sun Mar 07, 2004 11:44 pm

Post by blue60007 »

Well the intilization for a character is usually 'char' I don't think you can add strings via operators. :( Don't know... :?
Image
User avatar
oddball
Corporal
Posts: 44
Joined: Tue May 27, 2003 3:49 pm
Contact:

Post 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.
[VS-UK]Maj.OddBall[BnHQ]
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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 ++
}
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

predefinded

Post 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 " ".
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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...
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

well there ya go :)

and

local.string = (getcvar(thing1)) + ( getcvar(thing2))

too I guess
Image
User avatar
oddball
Corporal
Posts: 44
Joined: Tue May 27, 2003 3:49 pm
Contact:

Post 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?
[VS-UK]Maj.OddBall[BnHQ]
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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
}
Image
blue60007
General
Posts: 1247
Joined: Sun Mar 07, 2004 11:44 pm

Post by blue60007 »

\n = newline
\t = tab
\0 = null
\\ = \

I think a space could be add like: " " :?
Image
User avatar
oddball
Corporal
Posts: 44
Joined: Tue May 27, 2003 3:49 pm
Contact:

Post 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?
[VS-UK]Maj.OddBall[BnHQ]
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Script Files.txt

Post 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.
Last edited by tltrude on Fri Jun 04, 2004 9:01 pm, edited 1 time in total.
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post 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'
Image
User avatar
oddball
Corporal
Posts: 44
Joined: Tue May 27, 2003 3:49 pm
Contact:

Post 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




[VS-UK]Maj.OddBall[BnHQ]
blue60007
General
Posts: 1247
Joined: Sun Mar 07, 2004 11:44 pm

Post by blue60007 »

Oooh very nice! :D That'll help and minimize errors from clients not having a custom map...
Image
Post Reply