Posts: 756
Threads: 53
Joined: Nov 2011
Hi all.
I come from a C++ background so I am wondering what syntax declares a variable that can be recalled later.
From what I've seen alias declares variables/commands and echo can print the contents of that but I can't seem to get that to work.
I like the Cubescript reference but I found it hard to learn the bare basics of the syntax from it.
E.G.
[cubescript]// This file gets executed every time you start AssaultCube.
// This is where you should put any scripts you may have created for AC.
alias test 67 //I'm trying to declare a variable and assign a value to it
alias testscript
[
echo test //I'm trying to print the value of that variable
]
docident testscript "Test Script" //I'm trying to document this so it come up with the description when I type it[/cubescript]
It would appear [ and ] are the equivalent of { and } and semicolons are not required?
When I create a variable how do I specify between strings, integers, and floats?
Posts: 3,462
Threads: 72
Joined: Jun 2010
alias is weird compared to more normal languages.
It can be thought of like a container (like a box, nothing computer-science related), you can put anything in it. You can put methods (definitions, functions), variables (strings, numbers), or anything else in it.
Look at the scripts thread: http://forum.cubers.net/thread-38-post-199.html#pid199
Look at the quickknife script. I'll copy it here:
[cubescript]
alias quickknife [
if (!= (curweapon) 6) [melee]
attack
onrelease [ sleep 1 [ if (= (curweapon) 0) [weapon (prevweapon)] ] ]
]
bind Q quickknife
[/cubescript]
The main alias here is quickknife. It gets executed whenever you hit Q. However, you can make this alias, and then do:
[cubescript]
echo $quickknife
[/cubescript]
and then it will print out the script to the screen. You can think of an alias as a container that gets parsed whenever it gets executed by () or other execution methods.
If you aren't scared away from cubescript by now, check out some guides made by some of the best: http://cubescripts.tk/forums_smf2/index.php?board=7.0
You can also join the IRC to ask some questions. irc.gamesurge.net #cubescript
Posts: 756
Threads: 53
Joined: Nov 2011
28 Nov 11, 12:11AM
(This post was last modified: 28 Nov 11, 12:15AM by Felix-The-Ghost.)
I saw the quick knife script earlier and that'd what I learned from. The script I posted earlier doesn't seem to work, though. It doesn't print anything, even if I type echo $test.
The link you gave doesn't appear to work for me. Maybe I'll try it again later.
Can that autoexec file create global aliases for AC? Hmm.
Edit: typing manually works.
The testscript command doesn't seem to work, nor does the documentation appear in the console.
Hmm. Does this forum support inline code? Or does it make everything block style? E.G. the code earlier in this post.
Posts: 3,462
Threads: 72
Joined: Jun 2010
try putting 67 in []'s or ""'s
I'll port those forums over to my real host somtimes. They are on a free host, and I haven't done it yet because porting them requires a ton of MySQL hackery :( (maybe because I have to make myself admin, and reset my password)
Yes, it can. Every alias in AC is global O.O
Posts: 756
Threads: 53
Joined: Nov 2011
So I can't have a local, helper alias then? Like inside the while loops (I didn't see any for loops) That's okay I guess, but then I'd have to make sure they all have unique names (can't use simple x and y...
Posts: 3,462
Threads: 72
Joined: Jun 2010
And then prefixes became your best friend :P
Also, try putting the [ for test script on the same line as the declaration.
Posts: 756
Threads: 53
Joined: Nov 2011
28 Nov 11, 12:21AM
(This post was last modified: 28 Nov 11, 12:24AM by Felix-The-Ghost.)
Prefixes are a good idea.
This is what I have now:
[cubescript]// This file gets executed every time you start AssaultCube.
// This is where you should put any scripts you may have created for AC.
alias test 67
alias testscript[
echo $test
]
docident testscript "Test Script"[/cubescript]
The 67 worked as is according to the manual echo $test... test.
just the function alias seems to not declare correctly.
Edit: putting a space (I guess it's the delimiter) between the function name and the '[' did it. Now just the documentation doesn't work.
Posts: 3,462
Threads: 72
Joined: Jun 2010
28 Nov 11, 12:48AM
(This post was last modified: 28 Nov 11, 12:50AM by Ronald_Reagan.)
whynot?
:3
* Ronald_Reagan tests
It works, just make sure that you have a / infront of it.
Also, when making docs and menus, make sure you remember that it is a bit procedural. You make a menu (or doc), and each item after that goes into that menu (or doc), until you make a new menu (or doc).
Posts: 756
Threads: 53
Joined: Nov 2011
Mine does not work, even with the slash. It outputs 67 but does not show any documentation :(
Posts: 3,462
Threads: 72
Joined: Jun 2010
The documentation is what you get when you type a command, and dont hit enter. It would be like "/echo". There is an option to turn off the documentation, I think the key is F1 to toggle it. Test it with echo.
Posts: 756
Threads: 53
Joined: Nov 2011
28 Nov 11, 01:23AM
(This post was last modified: 28 Nov 11, 01:24AM by Felix-The-Ghost.)
It works with all commands, it is toggled on. /testscript doesn't get the doc showing though :(
Posts: 3,462
Threads: 72
Joined: Jun 2010
I see it :P
Sounds like a bug. Dont worry about it for now, docs aren't very critical. Menus and UI is mostly what makes scripts good or not I think. I also again encourage you to continue this conversation on IRC :)
Posts: 756
Threads: 53
Joined: Nov 2011
I wanted to be able to document scripts with parameters. The documentation doesn't show in the current version or the SVN. Oh well.
Posts: 3,462
Threads: 72
Joined: Jun 2010
Posts: 756
Threads: 53
Joined: Nov 2011
Yes, that worked. Did you just migrate? I see there are few posts.
Posts: 3,462
Threads: 72
Joined: Jun 2010
28 Nov 11, 04:10AM
(This post was last modified: 28 Nov 11, 04:10AM by Ronald_Reagan.)
I migrated just now.
That site actually has a long history of new hosts and such. It precedes (or close to, maybe a little after) me in the AC scene actually.
Posts: 3,780
Threads: 33
Joined: Jun 2010
28 Nov 11, 10:38AM
(This post was last modified: 28 Nov 11, 10:39AM by V-Man.)
Documentation using "docident" requires more arguments. Look at the default docs for a good example of the proper structure.
Or, if you'd like, you can see how I documented the tools.cfg commands -- based on the pattern visible in the default docs.
A word of wisdom: You'll want to avoid the quotes as much as possible, since they aren't "sided" -- meaning the engine will not nest them in a predictable way like it does with square brackets and parentheses.
Posts: 756
Threads: 53
Joined: Nov 2011
(28 Nov 11, 10:38AM)V-Man Wrote: Documentation using "docident" requires more arguments. Look at the default docs for a good example of the proper structure.
Or, if you'd like, you can see how I documented the tools.cfg commands -- based on the pattern visible in the default docs.
I see the script needs to be "installed" via execution rather than inside the autoexec itself. I copied the following anyway and didn't get any documentation to show up. Looks like some useful stuff in there :)
[cubescript]alias kickbots [
loop o $numargs [
kickbot (findpn (getalias (concatword "arg" (+ $o 1)))) ]]
docident [kickbots] [Kicks multiple bots out of a bot game.];
docargument [C] [Bot's client number];
docargument [...] [Up to 24 at a time.]
docexample [kickbots 2 4 6 8] [kicks bots with client number 2, 4, 6, and 8.];
docremark [For duplicate client numbers, will only kick one bot each.];[/cubescript]
Where in the tools.cfg does it call docsection.cfg?
(28 Nov 11, 10:38AM)V-Man Wrote: A word of wisdom: You'll want to avoid the quotes as much as possible, since they aren't "sided" -- meaning the engine will not nest them in a predictable way like it does with square brackets and parentheses.
Good advice. I didn't know the brackets could handle strings.
Posts: 3,780
Threads: 33
Joined: Jun 2010
28 Nov 11, 09:06PM
(This post was last modified: 28 Nov 11, 09:12PM by V-Man.)
What's missing there is the "docsection" command, telling the game that you're going to add to the in-game documentation (though I don't know exactly how crucial this is).
I'm assuming you're putting that code into autoexec.cfg?
If that's the case, it should show up in the in-game documentation.
In-game, type
/kickbots
but don't hit enter. If the documentation doesn't show up, hit F1.
The command
/docvisible 1
should also perform this function.
tools.cfg doesn't specifically call the documentation, there is a separate documentation file for it, "tools docsection.cfg". It is run after the default docs are run, starting its own docsections:
[code=CubeScript]
docsection [Math Tools]
docident [isfloat] [Checks whether a given input is a floating-point number.];
docargument [X] [The item to check];
docexample [echo (isfloat $fov)] [returns 1 since the fov value is in float format.];
// ...
docsection [Alias Tools]
docident [addcheck] [Checks a given alias and, if the given alias does not already have a given string, adds it in using add2alias (see docs regarding that default script).];
docargument [A] [The alias name];
docargument [C] [The command string to search and add in if it is not already in the given alias];
docexample [addcheck commandlist [echo "commands completed!"]] [At the end of executing the alias "commandlist", the given message appears.];
[/code]
Posts: 756
Threads: 53
Joined: Nov 2011
It's exactly the same problem I had with my testscript and that's almost the same advice Ronny gave me :/
Quote:What's missing there is the "docsection" command
This is problaby my problem, though. Thanks for showing me this -- I'll try it later.
Quote:tools.cfg doesn't specifically call the documentation, there is a separate documentation file for it, "tools docsection.cfg". It is run after the default docs are run, starting its own docsections:
I noticed a scripts directory that automatically executes all its contents on startup. Is that how your docsection gets called? Otherwise I don't see how the game would ever load it if nothing calls it.
Posts: 3,780
Threads: 33
Joined: Jun 2010
29 Nov 11, 12:44AM
(This post was last modified: 29 Nov 11, 12:45AM by V-Man.)
Ah!
In 1.1.0.4, the custom "scripts" directory is automatically executed if you have made an automatically executed scripts folder.
Basically, you put
[code=CubeScript]
execdir scripts
[/code]
in autoexec.cfg and all your scripts in there get run at startup, including the tools docsection.
Posts: 3,462
Threads: 72
Joined: Jun 2010
B_Man (whoops?), I tested the code he gave me (the docident stuff), and it worked through the commandline.
Posts: 3,780
Threads: 33
Joined: Jun 2010
29 Nov 11, 05:41AM
(This post was last modified: 29 Nov 11, 05:48AM by V-Man.)
(29 Nov 11, 12:58AM)Ronald_Reagan Wrote: B_Man (whoops?)
Talk to Wifey.
Posts: 756
Threads: 53
Joined: Nov 2011
30 Nov 11, 04:14PM
(This post was last modified: 30 Nov 11, 04:17PM by Felix-The-Ghost.)
I'm having some serious trouble with this syntax.
This script I made used to work to an extent, going one-way and echoing the value but not toggling it. Now I don't know what's wrong.
I'm trying to emulate a Boolean variable and act on it.
I'm trying to do this:
bool slow = false;
void toggle_slo_mo
{
slow = !slow;
if (slow)
gamespeed = 10;
else
gamespeed = 100;
}
[cubescript]
alias slow 0 //0 = normal speed 1 = slo_mo
alias toggle_slo_mo
[
if ( = $slow 0 ) //if slow is off
[
push slow 1; //turn slow on
gamespeed 10 //slow-mo
]
//else...
[
pop slow; //turn slow off
gamespeed 100 //normal-speed
]
echo $slow //debug
]
bind LALT toggle_slo_mo //no minimap for you
[/cubescript]
But it doesn't even echo the value, neither via LALT nor via manual typing the /toggle_slo_mo
Is a line-break a delimiter for commands as well as the semicolon?
I had tried removing it before and it ended up trying to combine the commands.
What methods are there for just assigning values to previously created aliases?
alias ali
ali = value? ali value? alias ali value?
Posts: 3,780
Threads: 33
Joined: Jun 2010
30 Nov 11, 05:30PM
(This post was last modified: 30 Nov 11, 05:51PM by V-Man.)
A hard return performs the same punctuation function as a semicolon (so ending a line with a semicolon is redundant).
You'll want the alias definitions, at least the starting brackets, to be on the same line to show the engine that you're explicitly beginning a new argument. After you open an argument, you can put whatever you want in it, including hard returns, without actually ending that particular argument (in other words, arguments can have multiple arguments within them; brackets group them as one). In general, the arguments of commands need to start on the same line as the argument before it.
So, for your script:
[cubescript]
alias slow 0 //0 = normal speed 1 = slo_mo
alias toggle_slo_mo [
if ( = $slow 0 ) [ //if slow is off
push slow 1; //turn slow on
gamespeed 10] [ //slow-mo
// else...
pop slow; //turn slow off
gamespeed 100 //normal-speed
]
echo $slow //debug
]
bind LALT toggle_slo_mo //no minimap for you
[/cubescript]
Note that closing brackets can come after any number of hard returns, as long as they are there (but the game does try to parse all white space, so you'll want only enough to make the script readable).
I didn't test the script, so I'm not sure how it'll work. XD
Think of an alias as a container. It only has what you tell it to have in it.
[cubescript]
alias examplealias 3
alias examplealias (- 5 2) // this will be calculated and stored when "alias" is run
examplealias = [- 5 2] // this will be stored as a function that finds "- 5 2" each time "examplealias" is run
// I see you found push and pop as well.
push examplealias (div 6 2)
pop examplealias
[/cubescript]
Almost forgot some other modifying commands:
[cubescript]
+= examplealias 2
-=f examplealias 2
*=f examplealias (divf $examplealias 3)
add2alias examplealias "bottles of beer on the wall"
[/cubescript]
(and there are some nice ones in tools.cfg as well.)
A nice note:
The "if" command's first argument, the evaluation, needs only a 1 or a 0. Thus, you can have for the evaluation something that will either be 1 or 0 (for example, $slow in your script). Then you'll want to swap the other two arguments:
[cubescript]
alias slow 0 / /0 = normal speed 1 = slo_mo
alias toggle_slo_mo [
if $slow [pop slow; gamespeed 100] [push slow 1; gamespeed 10]
echo $slow]
bind LALT toggle_slo_mo //no minimap for you
[/cubescript]
Posts: 3,462
Threads: 72
Joined: Jun 2010
Or if your me, your code ends up like this:
[cubescript]
alias slow 0 //0 = normal speed 1 = slo_mo
alias toggle_slo_mo [ if $slow [pop slow; gamespeed 100] [push slow 1; gamespeed 10] echo $slow]
bind LALT toggle_slo_mo //no minimap for you
[/cubescript]
Posts: 3,780
Threads: 33
Joined: Jun 2010
haha, that's useful for when you're entering a scripting contest that has a limit on the number of lines. :-P
Posts: 3,462
Threads: 72
Joined: Jun 2010
01 Dec 11, 04:03AM
(This post was last modified: 01 Dec 11, 04:03AM by Ronald_Reagan.)
Or you never explored why CS is so picky, and in what ways it is picky.
Posts: 1,436
Threads: 7
Joined: Jun 2010
(01 Dec 11, 03:50AM)V-Man Wrote: haha, that's useful for when you're entering a scripting contest that has a limit on the number of lines. :-P
Or when we start the International Obfuscated CubeScript Code Contest. Oh boy, that would be fun :D
Posts: 756
Threads: 53
Joined: Nov 2011
01 Dec 11, 11:21PM
(This post was last modified: 01 Dec 11, 11:22PM by Felix-The-Ghost.)
Awesome! The script now works as intended! You should try it with bots -- it's really fun jumping around a corner and splattering/headshotting a bot in slow motion and watching the gibs come out :)
I think I'll try to update the script by storing the sensitivity(s) and make them lower when in "bullet time" :P
I also thought about using megabind so that alt toggles in while watching a replay but not while playing. I'm not sure what key I can use that's easy to hit while actually playing. When you're typing a message do letter keybinds activate? I don't think they do meaning it'd be okay to bind a letter.
Thanks V-Man for the education on CS syntax -- some of that should be in the docs/reference.
|