Welcome to the Creatures Wiki! Log in and join the community.

RAL: Scripts & A Talking Lemon

From Creatures Wiki
Jump to navigation Jump to search

This article was imported from the RAL manual. However, it's about CAOS generally.

Opening

try as one might, it’s not edible

Now that you know the basics of CAOS, it’s time to move onto actually putting an agent into the world and giving it some behaviour. How?

Putting The Lemon In The World

First, get ahold of a lemon. The Lemon Pod, located to the top-left of the Norn Meso, is a good source of them.

Second, we need to find out what the spritesheet name and starting frame are.

While the mouse is over a lemon…​

> targ hots outs gall
ds lemon pod
> targ hots outv abba
30

These don’t change, but it’s useful to know these exist nonetheless.

The first output is referring to Docking Station/Images/ds lemon pod.c16.

The second output is referring to frame 30 of that file.

Finally, we need to create the lemon.

You can use Control-Shift-X to show X and Y coordinates underneath the Hand.

This guide will use 631 9158 as the coordinates.

> new: simp 2 24 8802 "ds lemon pod" 1 30 8000
OK

This creates the "lemon" in the world, but a position has not been given.

> rtar 2 24 8802 mvsf 631 9158
OK

This selects the lemon using rtar, which sets targ to a random instance of classifier 2 24 8802 (of which there should only be one right now).

It then places it using mvsf, which places the lemon near the target coordinates, trying to avoid intersection with walls.

Rather than using rtar 2 24 8802, you can instead use targ hots while hovering the mouse over the lemon, but this is likely to cause accidents if you aim in the wrong place.

Giving The Lemon Physics

> rtar 2 24 8802 perm 100 attr 199
OK

If you instead receive "Invalid map location (…​, …​)", consider moving the lemon to somewhere that is within the normal bounds of the game world.

The lemon should now slowly drop to the floor…​ and potentially start bouncing a lot.

> rtar 2 24 8802 aero 10 accg 2
OK

And that should make it stop bouncing.

Making It Talk

Now that we have an agent that we want to do stuff to, let’s try actually, well, doing something to it.

> rtar 1 2 10 mesg wrt+ targ 126 "Hello! I'm a talking lemon!" hots 0
OK

Breaking it down into its' constituent commands, we have:

  • rtar 1 2 10: Selects the Speech Bubble Factory, an agent which produces speech bubbles.
  • mesg wrt+ targ 126 "Hello! I’m a talking lemon!" hots 0: Sends message 126 "Make Speech Bubble" to the Speech Bubble Factory (as targ), with parameters "Hello, I’m a talking lemon!" (the text) and hots (the speaking agent, in this case whatever’s under the pointer). Important to note is that everything after mesg wrt+ is a valid expression.

Attaching A Script

This is the part where what is arguably just a random object becomes a talking lemon.

> scrp 2 24 8802 1 rtar 1 2 10 mesg wrt+ targ 126 "Hello! I'm a talking lemon!" ownr 0 endm
OK

And now just click the lemon, and it will say its line.

Breaking this down into it’s constituent components, we have:

  • scrp 2 24 8802 1: This begins script 1 on classifer 2 24 8802.
  • rtar 1 2 10: Selects the Speech Bubble Factory, an agent which produces speech bubbles.
  • mesg wrt+ targ 126 "Hello! I’m a talking lemon!" ownr 0: Sends message 126 "Make Speech Bubble" to the Speech Bubble Factory (as targ), with parameters "Hello, I’m a talking lemon!" (the text) and ownr (the speaking agent, in this case ownr).
  • endm: This ends the script.

Some further notes:

  • When a script is executing on an agent, ownr is the agent that the script is executing on.
  • Script number 1 is also known as Activate 1.
  • Scripts do not have to be defined in order.
  • Script definitions are installed before any other code in a CAOS file.
  • Script definitions are installed to the world for any agent that matches the classifier — i.e. if you were to follow the steps above to create this lemon again on the same world, it would already have the script.

Machine Variables (MVs) and Object Variables (OVs)

Every agent has 100 stored variables, known as Object Variables. This allows storing values outside of the current script.

Like va variables, they range from ov00 to ov99, and on a newly created agent, start as the number 0.

Some of these variables, such as ov60 and ov61, are reserved for the game’s internal use.

Referring to these variables with the ov prefix refers to the variables in the targ agent, while referring to them with the mv prefix refers to the variables in the ownr agent. The variables themselves are in the same place in the agent, it’s just that mv00 and ov00 look at ownr and targ respectively.

To see, run these two CAOS scripts (assuming you have exactly one talking lemon)

rtar 2 24 8802
sets ov01 "Some value!"
rtar 2 24 8802
outs ov01

Things To Check

  • Make the lemon say a message held in one of its machine variables.
  • Use a Constructor script to set perm, attr, aero, and accg of a lemon.
    • The Constructor script, script 10, is automatically run on creation of an agent.

External links