Game Scripting – Part 4 – The Guide! – Chapter 2
Last week in the guide, we covered how to create your first tag, for dialog, as well as some basics for the system. If you’re new to this guide, I highly recommend reading at least last week’s entry, but ideally you’d also check out the first intro post. And of course, the guide itself is pretty key.
Today we are going to cover some more crucial basics: Events and Conditions.
When you are scripting in the Map Editor, you’ll only use the script tag once. All your scripting must take place in between
<script>
and
</script>
Add any more of those tags and you’ll break the system. So how then do you tell the editor when to make things happen? If you want to build a cool level, you don’t want everything to happen all at once, right? You want some dialog at the start, maybe a few units to appear. In the middle of the level, maybe a mystery unit appears and a new character spouts off a challenge. Then at the end, your hero brags about his victory.
Well, each of those instances are part of an Event, and those Events are started by certain Conditions. So, you want to think in terms of Events if you want things to happen at certain points in your map. And this shouldn’t be a surprise by now, but your Event tags are:
<event>
</event>
In between those tags you’re going to put your Event info… which is anything you want to script to have happen. The trigger for that Event to start is the Condition. Here’s a sample Condition to show you how one should look, this one is for something to occur with the game starts:
<condition type="startGame">
</condition>
So, how would an Event and Condition look together? I’m glad you asked…
<event>
<condition type="startGame">
</condition>
</event>
That’s the little code sandwich you’ll place your scripting action inside of. So, if we want to have a character say something, we would do it like this:
<event>
<condition type="startGame">
</condition>
<response type="disableControllers">
<disable value="true"></disable>
</response>
<response type="chat">
<sender value="Captain Tucker"/>
<message value="You'll never get away with this, Durand."/>
<avatar value="tucker"/>
<color value="red"/>
</response>
<response type="disableControllers">
<disable value="false"></disable>
</response>
</event>
Add the script tags you need after that and you have a full map. But what if you want something to also occur at the end of the map? You want another Event my friend. Let’s make another one! We’ll want to change the Condition type from “startGame” to “endGame”. But be sure to review the .pdf guide for info on Conditions. There are a bunch!
Note that in the Condition we specify the Player by number and their Victory as true or false. True means that this player has won. False means that they did not. So, if you lose, you won’t see this text!
Now to business!
<event>
<condition type="endGame">
<player value="1"></player>
<victory value="true"></victory>
</condition>
<response type="disableControllers">
<disable value="true"></disable>
</response>
<response type="chat">
<sender value="Captain Tucker"/>
<message value="I'm the best!"/>
<avatar value="tucker"/>
<color value="red"/>
</response>
<response type="disableControllers">
<disable value="false"></disable>
</response>
</event>
But hey, let’s be fancy. Maybe we want to make sure the Player gets a new message if they lose the map. We can reuse the above code and make a very slight change to the Condition and the Chat.
<event>
<condition type="endGame">
<player value="1"></player>
<victory value="false"></victory>
</condition>
<response type="disableControllers">
<disable value="true"></disable>
</response>
<response type="chat">
<sender value="Captain Tucker"/>
<message value="I'm the worst!"/>
<avatar value="tucker"/>
<color value="red"/>
</response>
<response type="disableControllers">
<disable value="false"></disable>
</response>
</event>
Okay, let’s go ahead and throw that all together. This should give us a map with dialog at the start and the end… and better yet, variable text for the end depending on who wins!
<script>
<event>
<condition type="startGame">
</condition>
<response type="disableControllers">
<disable value="true"></disable>
</response>
<response type="chat">
<sender value="Captain Tucker"/>
<message value="You'll never get away with this, Durand."/>
<avatar value="tucker"/>
<color value="red"/>
</response>
<response type="disableControllers">
<disable value="false"></disable>
</response>
</event>
<event>
<condition type="endGame">
<player value="1"></player>
<victory value="true"></victory>
</condition>
<response type="disableControllers">
<disable value="true"></disable>
</response>
<response type="chat">
<sender value="Captain Tucker"/>
<message value="I'm the best!"/>
<avatar value="tucker"/>
<color value="red"/>
</response>
<response type="disableControllers">
<disable value="false"></disable>
</response>
</event>
<event>
<condition type="endGame">
<player value="1"></player>
<victory value="false"></victory>
</condition>
<response type="disableControllers">
<disable value="true"></disable>
</response>
<response type="chat">
<sender value="Captain Tucker"/>
<message value="I'm the worst!"/>
<avatar value="tucker"/>
<color value="red"/>
</response>
<response type="disableControllers">
<disable value="false"></disable>
</response>
</event>
</script>
Check back in next week when I’ll give you some pro tips for making shorter code blocks. We’ll also cover that weird “disableControllers” response I keep using as well as try some more advanced Conditions!


Sup Dog!!!!!
its me ive been on a long vacation.but it seems things are moving along.thats nice but ive been able to read other parts.some are just weird like the script parts.thats not necesary to me but others might like it.another problem i have is the beta testing.i cant get it to work but people who has post a commit for meon how to make it work or how cool it is.Sup Dog!!!!!
August 10th, 2009 at 12:44 pmSup Dog!!!!!
sry about that has and me on
August 10th, 2009 at 12:45 pmscarmichael
We’re actually in open beta… so you don’t need to do anything special to join now. Just show up to http://www.kongregate.com/games/urbansquall/battalion-arena and play!
August 12th, 2009 at 10:08 am