Config Logic tool

Discuss anything to do with Nexuiz here.

Moderators: Nexuiz Moderators, Moderators

Config Logic tool

Postby AceOfThumbs » Tue Mar 18, 2008 8:38 pm

Several people have been working on aliases to enhance the config scripting. I just wanted to pitch in with my own version. It is well documented below.

Here are some examples:

if $x eq "agressor" then agressor_setup else normal_setup
if_num $x ge 5 then echo "it's over 5" else do_nothing
for_num i from 10 to 110 by 10 do set_zoom
math circ eq $diameter mul 3.14

What's new in this version:
    input_number allows your alias to get a number that the player types
    input_digit allows your alias to get a signle digit that the player types
    aot_userbind stores your aliases in the user bind menu so the user can change the binds to his/her own preference without having to edit the config files


Download the file below and place it in your Nexuiz/data directory.
http://t2net.com/nexuiz/configplus_1_0.pk3

Then add this line to autoexec.cfg:
exec "configplus.cfg"

Note: In the original post I named the files config_logic, but since it goes beyond just logic statements now to various utilities, I renamed them configplus. If you've downloaded config_logic.pk3, delete it and replace with configplus for additional and improved functions.

Below is the documentation on the commands. Note that these are just the comments from the config file, not the actual commands. If you want to see the aliases for the commands, unzip the pk3.
Code: Select all
// -------------------------------------------------------------------------------------
// Config Plus v 1.0 -------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// If you have ideas or comments on Config Plus, please post them at alientrap.org/forum
// -------------------------------------------------------------------------------------
//
// Note that in the comments below two dollar signs are used instead of one dollar sign.
// This is because Nexuiz will try to replace a single dollar sign with a variable value
// even if the line is a comment. So anywhere you see $$ in a comment, it should really
// be a single dollar sign.
//
// -------------------------------------------------------------------------------------
//
// do_nothing does nothing which is handy in scripting sometimes

// if command --------------------------------------------------------------------------
// syntax: if value1 eq value2 then alias1 else alias2
//     or: if value1 ne value2 then alias1 else alias2
//         value1 and value 2 can be numbers or single-word strings
//         alias1 and alias2 can be commands or aliases and can
//           include parameters if quoted (see example)
//
// description: Works like a regular if command, but only allows tests for equal (eq)
//              or not equal (ne)
//
// example: alias my_true_alias "echo true"
//          alias my_false_alias "echo false"
//          set x 5
//          set y 7
//          set s "apple"
//          set s2 "spaced text"
//          if $x eq 5 then my_true_alias else my_false_alias
//          -> true
//          if $x ne 5 then my_true_alias else my_false_alias
//          -> false
//          if $x ne $y then my_true_alias else my_false_alias
//          -> true
//          if $s eq apple then "echo it is an apple" else my_false_alias
//          -> it is an apple
//          if "$s" eq "" then my_true_alias else my_false_alias
//          -> false
//          if "$s2" eq "spaced text" then my_true_alias else my_false_alias
//          -> true
//
//          The last 3 examples above use quotes since strings with spaces
//          and empty strings are used. Also use quotes around variables if they
//          might contain spaces or might be empty.
//          When you use if in an alias, you would need to use \" as in:
//          alias my_example "if $x eq 5 then \"echo x is 5\" else \"echo not 5\""

//
// if_num command --------------------------------------------------------------------------
// syntax: if_num value1 operator1 value2 then alias1 else alias2
//         value1 and value 2 must be numbers
//         operator1 is one of the following:
//           eq (equal)
//           ne (not equal)
//           gt (greater than)
//           lt (less than)
//           ge (greater than or equal to)
//           le (less than or equal to)
//         alias1 and alias2 can be commands or aliases and can
//           include parameters if quoted (see example)
//
// description: Works like the regular if command, but only with numbers and has more operators
//
// example: alias my_true_alias "echo true"
//          alias my_false_alias "echo false"
//          set x 5
//          set y 7
//          if_num $x lt 5 then my_true_alias else my_false_alias
//          -> true
//          if_num $x ge 5 then my_true_alias else my_false_alias
//          -> false
//          if_num $x ne $y then my_true_alias else my_false_alias
//          -> true
//
// warning: 1. If value1 or value2 are strings they will be treated as 0.
//          2. Must be used after Nexuiz loads. Use regular if during startup.
//             That is, using if_num in an alias or bind is fine if it runs
//             after Nexuiz loads, but it can't be used directly in autoexec.cfg
//             since the rpn calculator isn't loaded yet.

//
// for_pre command -------------------------------------------------------------------------
// syntax: for cvar1 to value1 do alias1
//         cvar1 is a variable name that is used for a loop counter
//         value1 can be a number from 2 to 20
//         alias1 can be a command or an alias and can
//           include parameters if quoted
//         for_pre_exit can be executed to leave the loop early
// description: Executes an alias up to 20 times, incrementing the
//                value of the loop variable each time it runs.
//              for_pre works when Nexuiz first loads.
//              The regular for only works after a game starts.
// example: alias my_count_alias "echo loop $i"
//          for_pre i upto 5 do my_count_alias
//          -> loop 1
//          -> loop 2
//          -> loop 3
//          -> loop 4
//          -> loop 5
// warning: The maximum number of loops is 20. Any other value is treated as a 1
//          If you need more, you would have to edit the for_pre code.


//
// for command -------------------------------------------------------------------------
// syntax: for cvar1 from value1 to value2 by value3 do alias1
//         cvar1 is a variable name that is used for a loop counter
//         value1, value2 and value3 are numbers
//         alias1 can be a command or an alias and can
//           include parameters if quoted
//         for_exit can be executed to leave the loop early
// description: Executes an alias in a loop, incrementing the
//                value of the loop variable each time it runs.
// example: alias my_count_alias "echo loop $i"
//          for i from 2 to 10 by 2 do my_count_alias
//          -> loop 2
//          -> loop 4
//          -> loop 6
//          -> loop 8
//          -> loop 10
// warning: 1. If value1, value2 or value3 are strings they will be treated as 0.
//          2. Must be used after Nexuiz loads. Use for_pre during startup.
//             That is, using if_num in an alias or bind is fine if it runs
//             after Nexuiz loads, but it can't be used directly in autoexec.cfg
//             since the rpn calculator isn't loaded yet.

//
// math command -------------------------------------------------------------------------
// syntax: math cvar1 eq value1 operator1 value2
//         cvar1 is the name of the variable that gets the result
//         operator1 is one of the following:
//           add, sub (subtract)
//           mul (multiply), div (divide)
//           mod (modulus), max (maximum), min (minimum)
//           The operators below return a 1 for true and a 0 for false:
//             eq (equal)
//             ne (not equal)
//             gt (greater than)
//             lt (less than)
//             ge (greater than or equal to)
//             le (less than or equal to)
//         value1 and value2 are numbers
// description: does a math or comparison calculation and stores the
//                result in the specified variable.
// example: set x 10
//          math x eq $x add 5
//          echo $x
//          -> 15
//          math x eq 100 div 3.5
//          echo $x
//          -> 28.571428
//          math x eq 5 gt 3.5
//          echo $x
//          -> 1
// warning: 1. If value1or value2 are strings they will be treated as 0.
//          2. Must be used after Nexuiz loads. Use for_pre during startup.
//             That is, using if_num in an alias or bind is fine if it runs
//             after Nexuiz loads, but it can't be used directly in autoexec.cfg
//             since the rpn calculator isn't loaded yet.

//
// input_number command -----------------------------------------------------------------
// syntax: input_number alias1
//         alias1 is the alias that is called, passing the number pressed as $1
// description: gets numbers pressed by player until enter is pressed
//              and stores the result in the specified variable.
// example: alias aot_inputfov "set fov $1"
//          bind b "input_number aot_inputfov"
//          [player types b then 130 then ENTER]
//          -> [fov is set to 130]
// warning: This only works in a game, since typing in the console just types.

//
// input_digit command ------------------------------------------------------------------
// syntax: input_digit alias1
//         alias1 is the alias that is called, passing the digit pressed as $1
// description: gets a single numeric digit pressed by player
//              and passes the result to the specified alias or command.
// example: alias tell_hi "tell #${1} hi"
//          bind b "input_digit tell_hi"
//          [player presses b then 3]
//          AceOfThumbs tells player #3 -> hi
// warning: This only works in a game, since typing in the console just types.

//
// aot_userbind command -----------------------------------------------------------------
// syntax: aot_userbind
// description: Searches userbinds for a specified bind name.
//              If found, it does nothing.
//              If not found, it searches for first empty slot and stores the bind.
//              If there are no empty lots, it does a normal bind
// example: set aot_userbind_key "MOUSE4"
//          set aot_userbind_name "quick_zoom - hold for 2x zoom"
//          set aot_userbind_alias "+aot_zoom_temp"
//          set aot_userbind_alias_release "-aot_zoom_temp"
//          aot_userbind
//          -> quick_zoom - hold for 2x zoom is in userbind 3

Last edited by AceOfThumbs on Wed Mar 19, 2008 11:17 pm, edited 1 time in total.
So much to do, so little time to do it
AceOfThumbs
Alien
 
Posts: 158
Joined: Tue Sep 04, 2007 11:12 pm

Postby Blµb » Tue Mar 18, 2008 8:42 pm

Great :)
Another config-freak ^^ hey :D

Code: Select all
(...)
// if command --------------------------------------------------------------------------
// syntax: if value1 eq value2 then alias1 else alias2
(...)
// warning: Error if value1 or value2 are strings with more than one word.
//          Error if value1 or value2 is the string "true" or "false".
//          Error if value1 or value2 is the empty string "".

Aliases can have spaces in them, you just need proper quoting
Code: Select all
alias strcmp "clf; alias \"strcmp_${2}\" \"\"; alias \"strcmp_${1}\" \"mov flag_z 1\"; \"strcmp_${2}\""

from my vmutil.cfg:
http://stud4.tuwien.ac.at/~e0725517/nex ... vmutil.cfg

flag_z is set to 1 if they equal
and the strcmp_ prefix makes sure that an empty string doesn't cause an error

then, the for_pre thing, menu_cmd can be used in the menu already :)

and the general math idea is nice =)

mhhh didn't know that toggle accepts more than just the cvar :)
nice to know that

EDIT

Yea right, my way is a bit stupid since it abuses aliases
but still, you with quotes you can make your way work in any case :)
Code: Select all
set temp "$str1"
toggle temp 0 "$str2" 1

temp will then be 1 if the strings equal
if you make an alias, use \"\"

Code: Select all
alias strcmp "clf; set flag_z \"$1\"; toggle flag_z 0 \"$2\" 1"


yay, thx, your config gave me some ideas :)

And it does work with empty strings
strcmp "" ""
strcmp "abc" ""
strcmp "" "abc"

all work correctly :)
Blµb
Alien trapper
 
Posts: 277
Joined: Thu Mar 29, 2007 1:49 pm

Postby AceOfThumbs » Wed Mar 19, 2008 11:22 pm

Blµb wrote:Aliases can have spaces in them, you just need proper quoting

Good tip, I've updated my code to allow spaces and empty strings. Thanks! :)
Blµb wrote:then, the for_pre thing, menu_cmd can be used in the menu already :)

I updated the comments to explain for_pre better. If you try to use menu_cmd during autoexec.cfg execution in Nexuiz 2.4, it can't find the command.
Blµb wrote:Yea right, my way is a bit stupid since it abuses aliases

I wouldn't say stupid. I think it was a clever way of doing it, just not the cleanest.
Blµb wrote:yay, thx, your config gave me some ideas :)

Your work inspired me too! :)

I've added some more commands and improved the old ones. See the first post in the thread for more details.

I hope others will share their ideas too. It would be great to get a unified toolkit that everyone can build off of. If anyone has ideas for more tools to include in configplus, please post or pm me and let me know.
So much to do, so little time to do it
AceOfThumbs
Alien
 
Posts: 158
Joined: Tue Sep 04, 2007 11:12 pm

Postby Mr. Bougo » Sat Mar 22, 2008 7:23 pm

AoT, the vmx86 Blub coded is greatness, I think it's good enough to be used for some binds!

The vm aliases can be used to code utils like if, that can be used for more adv. aliases :D
Mr. Bougo
Keyboard killer
 
Posts: 760
Joined: Mon Sep 10, 2007 3:29 pm


Return to Nexuiz - General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron