Forum

> > CS2D > Scripts > How do u use parse?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How do u use parse?

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How do u use parse?

danh
User Off Offline

Zitieren
Hi

Title sez it all...
Spoiler >
so yeh i dont get the ""s at 1st bit, at the end, and all the dots?

pls help

alt Re: How do u use parse?

DannyDeth
User Off Offline

Zitieren
The dots are joining all the strings together:
1
"hi ".."there!"
is the same as
1
"hi there!"
It's pretty simple. Also, that has nothing to do with the 'parse' function, it is part of Lua itself.

alt Re: How do u use parse?

ohaz
User Off Offline

Zitieren
between " and " is a String. Just words you wrote yourself. When " is over, they add .. and a variable.
1
2
3
name = "Peter"
print("Hello "..name)
-> Hello Peter

alt Re: How do u use parse?

DC
Admin Off Offline

Zitieren
your goal: get a string with a command and all required parameters in a format that CS2D understands (a format that you could also enter in the console and it would work). your parameters can be changed so their values are saved in variables.

this format is: "command param1 param2 param3..."
(parameters separated with spaces)

how you do it: you simply join the "strings" and variables with .. (.. is an operator to concatenate strings. you use + to add two numbers but .. to "add" two strings)

imagine the variable values are:
effect=1
x=2
y=3
p1=4
p2=5
r=6
g=7
b=8

then this
parse("effect "..effect.." "..x.." "..y.." "..p1.." "..p2.." "..r.." "..g.." "..b)

would result int:
parse("effect 1 2 3 4 5 6 7 8")

a valid command with parameters in the right format so that CS2D can execute it. that's it.

it's important that you add spaces. one space behind the command itself "effect_" and of course one space between all parameters "_". otherwise you would end up with: parse("effect12345678") which is nonsense. CS2D doesn't understand it.

hope that helps to understand the idea.


common mistakes:
many idiots use .."".. to attach an empty string to the string. it changes NOTHING and is always 100% pointless. it's like adding 0 to a number. it makes no difference. we use .." ".. to add WHITESPACES, but "" doesn't add anything because it's an empty string. " " and "" = huge difference!

some people add a space to the end .." ". this also makes no difference. CS2D doesn't care if the command ends with a space or not.

oh and you actually don't have to care about all this if you include and use wrapper.lua (but remove the map function from it! it's a bug)
1× editiert, zuletzt 17.09.11 11:53:33

alt Re: How do u use parse?

Apache uwu
User Off Offline

Zitieren
You can also use ' '.

It's useful if you want to include double quotes in your string.

1
mystring='my quotes "lol" are here'

It works with patters as well...

1
mystring="my quotes \"lol\" are here"
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht