Code: Select all
setcvar "mycvar" "value"Code: Select all
set mycvar "vaule"I saw these 2 way and both of them works.
Code: Select all
getcvar"mycvar"Code: Select all
getcvar(mycvar)Moderator: Moderators
Code: Select all
setcvar "mycvar" "value"Code: Select all
set mycvar "vaule"Code: Select all
getcvar"mycvar"Code: Select all
getcvar(mycvar)Code: Select all
setcvar "nextmap" getcvar(map2)Code: Select all
game.map_list = makeArray
(getcvar(map1))
(getcvar(map2))
(getcvar(map3))
(getcvar(map4))
(getcvar(map5))
endArrayCode: Select all
string_splitter local.mystring:
local.spitter = " "
local.splitter_conut = 0
local.splitter_count2 = (local.splitter_count + 1)
local.string[] = local.mystring
for(local.i = 0; local.i <= local.string.size; local.i++)
{ //check how many words are composing the string
if(local.string[local.i] == local.splitter)
local.splitter_count++
}
game.word_num = 1
for(local.i = 0; local.i <= local.string.size; local.i++)
{
if(local.string[local.i] != local.splitter)
{
game.word[game.word_num][game.char_num] = local.string[local.i]
game.char_num++
}
if(local.string[local.i] == local.splitter)
game.word_num++
if(game.word_num > local.splitter_count2 || game.word_num == local.splitter_count)
{
println "Error occurred during string splitting"
end
}
}
endCode: Select all
main:
local.maplist = getcvar(sv_maplist)
local.mystring = local.maplist
waitthread global/string_splitter.scr::string_splitter local.mystring
for(local.i = 1; local.i <= game.word_num; local.i++)
{
println (game.word[local.i])
}
endCode: Select all
local.string[] = local.mystringCode: Select all
dm/mohdm1 dm/mohdm2Use the "end" keyword and call the thread with "waitthread". For instance:SilentAngel wrote:ok, now my question is:
HOW CAN I MAKE MY SCR RETURN SOMETHIG??!
i mean something like return for C functions..becouse I would like to use it from separated scripts.
Code: Select all
local.var = waitthread get_some_value
(...)
get_some_value:
local.foo = "bar"
end local.fooCode: Select all
local.foo = "bar"
local.strlen = local.foo.size // 3yeah, I'm use to do useless stuff! lolNo need to copy local.mystring to local.string. local.mystring is not a reference or a pointer to the original variable, it's a copy and you can safely operate on it without risking corruption of the original data.
OOPS!I see some typos - splitter_count vs splitter_conut.
I know that but mine is a not a public script, so for now I'll use it with this "functional hole", maybe when I got some more time i'll do it better!Your word counter isn't exactly reliable. In the best case, you will miss the last word, in the worst (e.g. multiple spaces between words) - for example:
dm/mohdm1 dm/mohdm2
would be counted by your code as 3 words. It's better to count words as non-interrupted sequences of non-whitespace characters.
oooh that's nice..well you saved me..Use the "end" keyword and call the thread with "waitthread". For instance:
Code:
local.var = waitthread get_some_value
(...)
get_some_value:
local.foo = "bar"
end local.foo
As a result of the above, local.var will be assigned the "bar" string. There are no type restrictions - a thread can return anything (even arrays), as long as it fits in 1 variable.
String length:
Code:
local.foo = "bar"
local.strlen = local.foo.size // 3
Code: Select all
main:
level.maplist = getcvar(sv_maplist)
local.mystring = level.maplist
waitthread string_splitter local.mystring
for(local.i = 1; local.i <= level.word_num; local.i++)
{
println (level.word[local.i])
}
end
string_splitter local.mystring:
local.spitter = " "
local.splitter_count = 0
local.splitter_count2 = (local.splitter_count + 1)
for(local.i = 0; local.i <= ((local.mystring.size) - 1); local.i++)
{ //check how many words are composing the string
if(local.mystring[local.i] == local.splitter)
local.splitter_count++
}
level.word_num = 1
level.char_num = 1
for(local.i = 0; local.i <= ((local.mystring.size) - 1); local.i++)
{
if(local.mystring[local.i] != local.splitter)
{
level.word[level.word_num][level.char_num] = local.mystring[local.i]
level.char_num++
}
if(local.mystring[local.i] == local.splitter)
level.word_num++
if(level.word_num > local.splitter_count2 || level.word_num == local.splitter_count)
{
println "Error occurred during string splitting"
end
}
}
end
Code: Select all
Type 'array'well I didn't know of it..I'll try, if you say it's well made and easy to understeand, I'll use it!Why make one yourself? Elgan has made an excellent set of string-utilities including the splitting of strings. In fact it's the only script I use that's not made by myself. Download his AP menu, the global/strings.scr is in there.
I love scripting and programming so I try to learn things doing some stuff I never done(ex. string splitter)!Why make one yourself?
Code: Select all
mythread:
local.result = waitthread do_stuff
//....
end
do_stuff:
//...
end local.result