cvar question..

Post your scripting questions / solutions here

Moderator: Moderators

SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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)
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post 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.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post by SilentAngel »

I see..ty :wink:
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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!
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

AFAIK nextmap is not used in MoHAA. The server uses sv_maplist only.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post by SilentAngel »

humm..whatta bad news for me! :?
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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??
Last edited by SilentAngel on Thu May 07, 2009 7:31 pm, edited 5 times in total.
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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:
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post 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.
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
SilentAngel
Captain
Posts: 239
Joined: Wed Mar 12, 2008 8:27 pm

Post 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)!
$oldier Of Ra
Lieutenant Colonel
Posts: 404
Joined: Sun Oct 16, 2005 7:16 pm
Location: Belgium
Contact:

Post 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
Our official website: http://www.mohaairborne.co.cc
(Still accessible through http://mohaaclantb.tk and http://users.skynet.be/mohaaclantb/)

For all your bot needs!!!!

$oldier Of Ra.
Post Reply