More blah blah on scripts:
If you bring the Pick Script dialog again for the mushroom,
you will see that your script populates the dialog (assuming you already wrote one).
You can change it, by removing events and actions, and write other rules.
Notice that no matter how much mushrooms you put in your level, they will all behave
the same OnUse event - they will all increase the strength by +1.
If you want to have different mushroom that does something else when eaten,
you have to add another game object to the Level editor.
For this, see How To Add New Game Objects to Level Editor tutorial.
Other examples of Usable items would be: Apple, Key, Spell, Wand...
and examples of Equipable items are: Axe, Shield, Helmet, Ring, Bracelet...
It is allowed for item to be both Usable and Equipable (chocolate dagger?),
all that checking does is adding Events specific to that type of pickable object.
These events are defined for pickable items:
DefaultEvents:
OnApproach - event happens when player approaches item
OnPick - event happens when player picks item
OnDrop - item is dropped
OnCombine - item is combined with another item
Events specific to equipable items:
OnEquip - event happens when player equips item (curses here we go)
OnUnequip - and this is when item is removed from the body
Events specific to usable items:
OnUse - In case of apple, this would represent eating it, in case of wand it would represent firing it
OnUseAgainst - This event is fired when item is clicked against other game object
List of all possible actions is big, and rising, and can be found in file media/Scripts/actions.script
Actions:
Disintegrate - deletes object from the map, weather it is mushroom you just eated, or a whole castle.
InfluenceAbility - Changes one ability score by the given value
InfluenceSkill - Changes selected skill score by the given value
InfluenceState - Changes state of selected object
Info - Writes message to game info console
LeadToMap - Loads another level (this action is called when player clicks on the door, for example)
... to mention just a few.
Programming Tutorial: Scripts
Scripts are introduced in attempt to remove programming from game making.
Programming is slow and hard and messy, and games are bigger and bigger.
But scrips usually end up just moving programming from one language (C,C++) to another (Lua, GameMonkey).
And not much is changed.
That is why we introduced completely new scripting system, designed to bring
as much ease as possible to game creation, without restricting the imagination.
Event! Condition? => Action:
Event Condition Action (ECA) System reduces scripting to predefined constants that can be
combined to desired effect. "Event" is something that happens in game, system is using events to
notify when player clicks on something, picks an item, opens a chest, attacks a monster...
Events have descriptive names like:
- SCRIPT_EVENT_CONTAINER_ONCLICK
- SCRIPT_EVENT_PICKABLE_ONPICK
- SCRIPT_EVENT_PICKABLE_ONUSE
- SCRIPT_EVENT_TRIGGER_ONCLICK
- etc.
Event constants should cover everything that can happen in your game, that requires some action in return.
Events for almost all possible situations are added to the system, if you need more you have to do some
programming. See Programming Tutorial for Adding Events to the Script System.
Condition is something that is checked before executing an action. It is optional variable, and can be
left out. You are free to define any condition you like without programming. Just add id to the list
of conditions in file media/Scripts/conditions.xml
This is how it works: You name a condition to describe the situation, for example, CONDITION_PLAYER_DRUNK.
You set condition initially to be false. When you write your script, you can now check if your player is drunk,
by checking the named condition variable. You can change the state of that variable in your game using actions.
Event "Player Drinks Beer" => Action "Change Condition CONDITION_PLAYER_DRUNK to true"
Event "Player Drinks Beer" Condition "CONDITION_PLAYER_DRUNK = true" => Action "Player pass out".
Action is what you do when event occurs.
With actions you can move things around, make them dissaper, influence player abilities, change states of objects...
the more the merrier.
Finally, all actions can be combined with all events and conditions, thus making your own game rules any way you like:
If player drinks beer => His strength goes up by 1.
If player eats mushroom => His house disappears.
If player clicks on the tree => tree falls down.
If player clicks on the tree (and he is drunk at the same time) => his strength goes up by 1.
Will this game rules make sense, it is entirely up to your conscience.
If you have loads of questions after these tutorials, like: "Whats with the strength attribute?
What other attributes exist? Can I add my own attribute? Skills? HP? Magic? Defense? Attack?"
Then you seem to be on a good track. Writing scripts is where you stop following tutorials,
and start making your own game rules.