Page 3 of 4

Posted: Sun Apr 26, 2009 12:56 pm
by SilentAngel
Where is the difference if I do this in a script:

Code: Select all

setcvar "mycvar" "value"
or if I do this in my cfg:

Code: Select all

set mycvar "vaule"
also I don't get the difference between these 2 ways to getcvar;
I saw these 2 way and both of them works.

Code: Select all

getcvar"mycvar"
or

Code: Select all

getcvar(mycvar)

Posted: Sun Apr 26, 2009 3:55 pm
by $oldier Of Ra
Setcvar is a scripting command. Set is a config commands.
Other than that there's no difference, both do exactly the same.

There's no difference. The scripting language just has very elastic rules therefor multiple syntaxes are possible.

Posted: Sun Apr 26, 2009 6:42 pm
by SilentAngel
I see..ty :wink:

Posted: Wed May 06, 2009 9:03 pm
by SilentAngel
and...
can I do that?

Code: Select all

setcvar "nextmap" getcvar(map2)
more exactly, I mean to set a cvar with the value of another cvar

and still talking about cvars..something like that:

Code: Select all

game.map_list = makeArray
(getcvar(map1))
(getcvar(map2))
(getcvar(map3))
(getcvar(map4))
(getcvar(map5))
endArray
will case problems or not works?
I'm asking you becouse the console didn't retourn me errors..but the mod doesnt work!

Posted: Thu May 07, 2009 1:04 pm
by SilentAngel
I've fixed array problem, but still don't get the first to work!!

any advice to do that:
setcvar "nextmap" getcvar(map2)
humm..console didn't display any message, but nextmap cvar is not set as I want!
I mean to set a cvar with the value of another cvar

Posted: Thu May 07, 2009 2:39 pm
by Rookie One.pl
AFAIK nextmap is not used in MoHAA. The server uses sv_maplist only.

Posted: Thu May 07, 2009 3:00 pm
by SilentAngel
humm..whatta bad news for me! :?

Posted: Thu May 07, 2009 4:14 pm
by SilentAngel
ok..I've made this little tool to split strings so that I can get maps from sv_maplist cvar:
(I did not tested it, so if you find errors correct me please!)

Code: 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
    }
    
}
end
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.
can I use game vars for that?
for exemple:
(remember that I have defined game vars and arrays in the "string splitter" scr)

Code: 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])
}
end
would this print in console maps name of sv_maplist one by one??

Posted: Thu May 07, 2009 4:26 pm
by SilentAngel
also I think this is not the right way:

Code: Select all

local.string[] = local.mystring
but I HAVE to do that..I don't know how in MOH scr leng!
advices? :evil: :cry:

Posted: Thu May 07, 2009 8:29 pm
by Rookie One.pl
OK, I don't really have time to check out the logic behind your code, but here's a few comments off the top of my head.

No 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.

I see some typos - splitter_count vs splitter_conut.

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:

Code: Select all

 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.

Why use the game object? If you want to achieve cross-thread variable visibility, use the level object instead. Game variables are known to be problematic.
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.
Use the "end" keyword and call the thread with "waitthread". For instance:

Code: Select all

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: Select all

local.foo = "bar"
local.strlen = local.foo.size // 3

Posted: Thu May 07, 2009 8:44 pm
by SilentAngel
No 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.
yeah, I'm use to do useless stuff! lol
I see some typos - splitter_count vs splitter_conut.
OOPS!
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.
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!
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
oooh that's nice..well you saved me..
ty man

Posted: Thu May 07, 2009 9:54 pm
by SilentAngel
this is the way I chose to check my script:

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

...everything seems going good, no lenguage error in console, BUT, instead of all my maps, the message in console is this:

Code: Select all

Type 'array'
what's up? why?! lol

Posted: Fri May 08, 2009 10:04 pm
by $oldier Of Ra
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.

Yes, nextmap is used in MoHAA by the bsptransition and leveltransition commands.

You are printing arrays because for some reason you're using 2 dimensions for simple string spitting and you are only printing the 1st dimension.

Posted: Sat May 09, 2009 10:59 am
by SilentAngel
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.
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?
I love scripting and programming so I try to learn things doing some stuff I never done(ex. string splitter)!

Posted: Sat May 09, 2009 11:14 am
by $oldier Of Ra
It's not good to build an dynamic thread on 1 level variable.

Code: Select all

mythread:
local.result = waitthread do_stuff

//....

end


do_stuff:

//...

end local.result