development, tutorial

[code] Picking a random letter in CAOS

Malkin approached me on Discord, asking me how to pick a random letter. I’ve been using random numbers in CAOS with the RAND command for like forever, but I hadn’t found a reason yet to pick random letters. The question made me think, though.

Of course, there’s the old-fashioned, boring and bulky-code-way of just picking a random number between 1 and number-of-letters-in-the-alphabet. Then you can set a variable to a letter depending on the value of that number, in an if-elif-elif-elif-elif-… scenario.

Surely there should be a cleaner/easier way!

Recently I learned more about the CHAR variable thanks to Amaikokonut’s blog post over at Naturing :: Nurturing. I noticed char has two commands, one that returns a variable and one that sets a variable.

The command returning the character returns the ASCII number for that character.
I wondered if the one setting a variable also uses the ASCII code for a character: Yup!

So, all that’s left is to figure out the ASCII numbers of the characters you want to use.

For the characters A to Z, that’s 65 to 90. For the characters a to z, that’s 97 to 122.

So if you want a character between a to z, the resulting code would be this:

sets va00 “a”
setv va01 rand 97 122
char va00 1 va01

Nice and clean, right? 😀

 

Advertisements
tutorial

[Code] How to make a door agent in C3/DS

I wrote up a quick tutorial on how to write a CAOS script to make a door for C3/DS.
I posted it over at the creatures wiki (since their formatting is nice and simple, and it’s pretty fitting for tutorials.)

You can find the door tutorial here

Enjoy!

development

[Code] Make an .agents file

You’ve probably read some tutorials here and there and tried to make a .cosfile on your own. Now the thing is, how do you actually get a neat .agents file that will show up in the agent injector?

I’ll teach you.

What do you need?

  • Monk (from the Jagent suite)
  • A folder containing your .cos script and any attachments you need (.c16, .catalogue, sound files, …)

What about EasyPray? And a prayfile?

Not needed. We’ll use Caos2Pray. There is an excellent explanation in this article on Naturing :: Nurturing.

The only thing it misses is an example of the *# LINK command, a very useful command I will explain further below.

For this case, we’ll go with making an easy script. You know, the tiny empathic vendor thing in the workshop? That little floating thing? It always annoyed me that I couldn’t separately inject it. But no more, I’ll teach you how to make it show up in the agent injector.

What are we going to do?

  • Create an instance of the empathic vendor ingame
  • Move it to the agent injector
  • Create the CAOS2Pray and compile the script into an agent.

For now, just open CAOS tool and create a new file.

Create an instance of the empathic vendor ingame

Since this is an existing object which gets loaded when the world gets loaded, the script is placed in the bootstrap/010 Docking Station/ folder. We need to know the classifier of the existing empathic vendor to be able to create a new one that uses the same script.

Feel free taking your time to browse in the bootstrap folder and learn what stuff you can find here. For now, we need the mini empathic vendor script. This script is called mini empathic vendor.cos. Open it and search for the bit where the vendor gets injected into the world.

** Create the Vendor
new: comp 2 23 9 “mini_vendor” 23 0 3000
attr 198
perm 60
accg 5
elas 0
bhvr 3
anim [0 1 2 3 4 5 6 7 8 9 10 11 255]
seta va00 targ

*** Move it to the workshop
*mvto 4800 9400

*move it into the chamber
rtar 1 1 154
doif targ ne null
seta va01 targ
spas va01 va00
else
targ va00
mvto 4800 9400
endi

Copy this into your cosfile.

We won’t need the part where the vendor gets moved into the workshop and the chamber, so you can entirely remove that part. Also, since va00 is being used to make the containment chember pick up the correct agent, that’s not needed either.

You can remove the bottom half of the script until you’re left with this:

** Create the Vendor
new: comp 2 23 9 “mini_vendor” 23 0 3000
attr 198
perm 60
accg 5
elas 0
bhvr 3
anim [0 1 2 3 4 5 6 7 8 9 10 11 255]

This creates an instance of the empathic vendor. Now we only have to move it to the agent injector.

Move to the agent injector

The ‘move something somewhere safely’ command is mvsf X Y.

The X and Y values of the agent injector are stored as game variables CreatorX and CreatorY, so the final piece of code would be this:

mvsf game “CreatorX” game “CreatorY”

Great!

You now made a cosfile that injects a mini empathic vendor in the agent injector space.

For completeness, you should now add a removal script on the end that removes every mini empathic vendor in the world.

** rscr indicates a removal script
rscr
** enumerate over all mini empathic vendors and target them
enum 2 23 9
** kill them
kill targ
** End the enumeration loop
next

If you manage to have CAOS tool working with your game, you could now inject the cos script by going through Inject – Inject install script (f9) or Inject install and event scripts (f11). If CAOS tool can’t communicate with your game, no worries, we’ll create a CAOS2PRAY chunk on top of this cosfile now, so we can compile it with Monk.

Create a CAOS2PRAY chunk

If you haven’t read the post on Naturing :: Nurturing yet, I urge you to do so now. It will help you understand the next part.

At the top of your .cosfile, add this chunk of text:

* CAOS2PRAY CHUNK
*# Pray-File “miniempathicvendor_YOURNAME.agents”
*# DS-Name “Mini Empathic Vendor (DS)”
*# depend mini_vendor.c16
*# desc = “This is a mini empathic vendor.”
*# Agent Animation File = “mini_vendor.c16”
*# Agent animation String = “0 1 2 3 4 5 6 7 8 9 10 11 255”
*# Agent Sprite First Image = 0
*# Agent Animation Gallery = “mini_vendor.c16”
*

This is pretty much all you need.

The total .cosfile should now look like this:

* CAOS2PRAY CHUNK
*# Pray-File “miniempathicvendor.agents”
*# DS-Name “Mini Empathic Vendor (DS)”
*# depend mini_vendor.c16
*# desc = “This is a mini empathic vendor.”
*# Agent Animation File = “mini_vendor.c16”
*# Agent animation String = “0 1 2 3 4 5 6 7 8 9 10 11 255”
*# Agent Sprite First Image = 0
*# Agent Animation Gallery = “mini_vendor.c16”
*
** Create the Vendor
new: comp 2 23 9 “mini_vendor” 23 0 3000
attr 198
perm 60
accg 5
elas 0
bhvr 3
anim [0 1 2 3 4 5 6 7 8 9 10 11 255]
mvsf game “CreatorX” game “CreatorY”
** rscr indicates a removal script
rscr
** enumerate over all mini empathic vendors and target them
enum 2 23 9
** kill them
kill targ
** End the enumeration loop
next

You can now save your cosfile, open Monk, drag & drop your cosfile on Monk, and… The magic happens! An agent called “miniempathicvendor.agents” is now in the folder where your .cos file originally happened to be.

miniemven.gif

Put the agent in your agents/ folder, make sure that you click on the ‘chat’ tab before reopening the agent injector window, and your agent should now show up under “Mini Empathic Vendor (DS)”.

That’s it!

 

Extra for advanced users: the “link” command

The *# link command syntax is like this:

*# link cosfile1.cos cosfile2.cos cosfile3.cos

This would be handy incase you’re making a metaroom project, for example, and have each toy, plant and animal coded in its separate .cos file, which you can then compile into one huge .agents file.

You don’t have to link the cosfile you run this command from.

 

I hope you found this post useful. 🙂

development, tutorial

[Code] Setting up a development environment for Docking Station

Hello all!

I will occasionally post some coding tutorials and other commented code for Docking Station here.

In this post I’ll show the development environment I’m using, and I’ll explain you how to set up your own under Windows 10.

Continue reading “[Code] Setting up a development environment for Docking Station”