Mr. Goodbar
08-11-2005, 04:14 PM
I seem to notice that not a lot of people on these forums dont know how to use the scripting engine, or at least use it well. Before reading this, it would help to have a bit of programming background, though it certainly isnt required. Let's dive right in to it then!
Before you start
Just a few things to remember. When you're using this thing, you're programming. Have fun and gloat about it! Also, end every command with a semicolon (this thing';').
expressions & variables
(numbers)
To use the scripting engine, you need to use numbers. That's all there is to it. Everything you can do with it absolutely requires them. Variables are what numbers get stored in. Consider the following code:
a = 10;
That creates a variable named 'a' and makes it worth 10. A variable can be named whatever you want, as long as it starts with a letter.
Expressions and operators do things with variables. There are 5 operators, and I certainly hope you know what 4 of them are.
a = 5+3;
b = 9-4;
c = 3*8;
d = 72/12;
e = 37%7;
a is given the value of 5+3, which is 8.
b is now 9-4, which is 5.
c is 24, because the asterisk (shift+8, '*') means multiplication here.
d is 6, because division is a forward slash.
e is trickier. It has the value 2, because '%' means modulous, which returns the remainder when two numbers are divided. so 7 goes into 37 evenly 5 times, after which, 2 is left over.
A few more operators:
a += 5; increases a's value by 5
a -= 2; decreases a's values by 2
a *= 7; multiplies a by 7
a /= 5; divides a by 5
b = 1+1 == 2; makes b true
c = 2+3 == 4; makes c false
d = 4 != 7; makes d true, because 4 does not equal 7
functions
functions are what makes the script actually do something. Whether it be cause a nuclear-scale explosion, or gently toss a baseball, functions are responsible. A full set of functions is listed on the 8'th part of the instructions provided with the scripting engine. I'll list the ones I feel are important. I never use half of the ones there. A few notes, for functions requiring positions, the room is 550 pixels on the X-axis, and 400 high on the Y-axis. (0, 0) is at the top left corner.
say(text,time), make sure you include text in quotes if it includes letters. you can also make text -----be a variable or number
explode(x,y,power), makes an explosion at position x, y with set power. 1 is normal for power
create(objectType,x,y,xVelocity,yVelocity) valid objectType strings: "baseball", "molotov", -----"bowlball", "bouncyball", "grenade", "fireball", "mine", "baby", "orb", "radio", "vortex". Returns -----the unique objectName assigned to the object you created.
-----destroy(objectName) removes specified object (if destructable)
addConstraint(objectName,x,y,len) the set object can't go farther than len pixels
resetForces() resets all added forces (constraints, springs, etc.)
water(x, y, xv, yv, lifeSpanInFrames, strength, spread, size, disappearOnContact), self
----- explainitory, experiment with this one
fireClip(x, y, xv, yv, lifeInFrames, scale) I can't get this to work. Just create a fireball to set things -----on fire
addBuddyVel(x,y)
setBuddyVel(x,y)
setBuddyPos(x,y)
addBuddyRot(rotationAmount)
setBuddyRot(angleRadians)
getBuddyX()
getBuddyY()
getEmotion() returns happiness of buddy from -100.0 to 100.0
getXV(objectName) returns x velocity of object, valid strings for objectName: "body", "rArm", "lArm", "rLeg", "lLeg", plus all strings returned by 'create' function (see ex-throwableBall)
getYV(objectName) ... y velocty ...
getX(name) ... x position ...
getY(name) ... y position ...
-----the above are self-explainitory
I think the special branching functions in the help script #9 say enough. But here they are:
if(value,arg1,arg2)
This is the if statement in ShockScript. It is actually set up like a function, but it works differently. First it evaluates 'value'. If it is true, then 'arg1' is evaluated and returned. Otherwise 'arg2' is evaluated and returned. Note that after 'value' is evaluated, either 'arg1' or 'arg2' will be evaluated, not both.
loop(num,arg)
This function evaluates 'arg' for 'num' number of times (the maximum is 2000)
I dont use the rest of them, except occasionally firstRun();
fun tricks
make something happenonece in a while
i=i+1;
if (i%100==0, doSomething());
the above makes doSomething() happen every 100 times the script runs (5 seconds on my computer).
create("fireball", getBuddyX(), getBuddyY(), 0, 0);
best way to set the buddy on fire
You can see some of my scripts to use as examples in my other post in featured games. I'll also answer any questions you have. Uhhh, comment away!
Before you start
Just a few things to remember. When you're using this thing, you're programming. Have fun and gloat about it! Also, end every command with a semicolon (this thing';').
expressions & variables
(numbers)
To use the scripting engine, you need to use numbers. That's all there is to it. Everything you can do with it absolutely requires them. Variables are what numbers get stored in. Consider the following code:
a = 10;
That creates a variable named 'a' and makes it worth 10. A variable can be named whatever you want, as long as it starts with a letter.
Expressions and operators do things with variables. There are 5 operators, and I certainly hope you know what 4 of them are.
a = 5+3;
b = 9-4;
c = 3*8;
d = 72/12;
e = 37%7;
a is given the value of 5+3, which is 8.
b is now 9-4, which is 5.
c is 24, because the asterisk (shift+8, '*') means multiplication here.
d is 6, because division is a forward slash.
e is trickier. It has the value 2, because '%' means modulous, which returns the remainder when two numbers are divided. so 7 goes into 37 evenly 5 times, after which, 2 is left over.
A few more operators:
a += 5; increases a's value by 5
a -= 2; decreases a's values by 2
a *= 7; multiplies a by 7
a /= 5; divides a by 5
b = 1+1 == 2; makes b true
c = 2+3 == 4; makes c false
d = 4 != 7; makes d true, because 4 does not equal 7
functions
functions are what makes the script actually do something. Whether it be cause a nuclear-scale explosion, or gently toss a baseball, functions are responsible. A full set of functions is listed on the 8'th part of the instructions provided with the scripting engine. I'll list the ones I feel are important. I never use half of the ones there. A few notes, for functions requiring positions, the room is 550 pixels on the X-axis, and 400 high on the Y-axis. (0, 0) is at the top left corner.
say(text,time), make sure you include text in quotes if it includes letters. you can also make text -----be a variable or number
explode(x,y,power), makes an explosion at position x, y with set power. 1 is normal for power
create(objectType,x,y,xVelocity,yVelocity) valid objectType strings: "baseball", "molotov", -----"bowlball", "bouncyball", "grenade", "fireball", "mine", "baby", "orb", "radio", "vortex". Returns -----the unique objectName assigned to the object you created.
-----destroy(objectName) removes specified object (if destructable)
addConstraint(objectName,x,y,len) the set object can't go farther than len pixels
resetForces() resets all added forces (constraints, springs, etc.)
water(x, y, xv, yv, lifeSpanInFrames, strength, spread, size, disappearOnContact), self
----- explainitory, experiment with this one
fireClip(x, y, xv, yv, lifeInFrames, scale) I can't get this to work. Just create a fireball to set things -----on fire
addBuddyVel(x,y)
setBuddyVel(x,y)
setBuddyPos(x,y)
addBuddyRot(rotationAmount)
setBuddyRot(angleRadians)
getBuddyX()
getBuddyY()
getEmotion() returns happiness of buddy from -100.0 to 100.0
getXV(objectName) returns x velocity of object, valid strings for objectName: "body", "rArm", "lArm", "rLeg", "lLeg", plus all strings returned by 'create' function (see ex-throwableBall)
getYV(objectName) ... y velocty ...
getX(name) ... x position ...
getY(name) ... y position ...
-----the above are self-explainitory
I think the special branching functions in the help script #9 say enough. But here they are:
if(value,arg1,arg2)
This is the if statement in ShockScript. It is actually set up like a function, but it works differently. First it evaluates 'value'. If it is true, then 'arg1' is evaluated and returned. Otherwise 'arg2' is evaluated and returned. Note that after 'value' is evaluated, either 'arg1' or 'arg2' will be evaluated, not both.
loop(num,arg)
This function evaluates 'arg' for 'num' number of times (the maximum is 2000)
I dont use the rest of them, except occasionally firstRun();
fun tricks
make something happenonece in a while
i=i+1;
if (i%100==0, doSomething());
the above makes doSomething() happen every 100 times the script runs (5 seconds on my computer).
create("fireball", getBuddyX(), getBuddyY(), 0, 0);
best way to set the buddy on fire
You can see some of my scripts to use as examples in my other post in featured games. I'll also answer any questions you have. Uhhh, comment away!