User Tools

Site Tools


scripting:other_language_features

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
scripting:other_language_features [2020/01/28 17:50] – external edit 127.0.0.1scripting:other_language_features [2023/05/15 02:31] (current) mit
Line 4: Line 4:
 To link files into your script, use the format.. To link files into your script, use the format..
  
-<codedoc>+<code>
 #include "<FILENAME>" #include "<FILENAME>"
-</codedoc>+</code>
 e.g. e.g.
 **ServerScript.mit** **ServerScript.mit**
-<codedoc>+<code>
 #include "CrowTournament.mit" #include "CrowTournament.mit"
-</codedoc>+</code>
 **CrowTournament.mit** **CrowTournament.mit**
-<codedoc>+<code>
 Event( "Custom", "StartCrowTournament" ) Event( "Custom", "StartCrowTournament" )
 { {
Line 19: Line 19:
     ...     ...
 } }
-</codedoc>+</code>
 Keeping related code separated like this can make it easier to share script across worlds - e.g. You could add your crow tournament feature to another world by copying the ''CrowTournament.mit'' file across and including it from the ServerScript. Keeping related code separated like this can make it easier to share script across worlds - e.g. You could add your crow tournament feature to another world by copying the ''CrowTournament.mit'' file across and including it from the ServerScript.
 +
 +===== Persistent Key Values =====
 +
 +You can create persistent/saved variable & data that are attached to a player, a building or the world/server. Keys are referenced by their name, can be created at any point and can store integers or strings.
 +
 +<code>
 +Event( "AccessBuilding", "" )
 +{
 +   $gPlayerKey[AccessCount] += 1
 +   $gBuildingKey[LastPlayerAccessed] = $gPlayerID
 +   $gServerKey[LastBuildingAccessed] = $gBuildingNum
 +}
 +</code>
 +
 +Barring sudden outages, key values will be saved and restored whenever the server is restarted.
 +
  
 ===== Timers ===== ===== Timers =====
Line 50: Line 66:
 Functions are defined in your script as shown in this example: Functions are defined in your script as shown in this example:
  
-<codedoc>+<code>
 Function IsItemASword( $itemNum ) Function IsItemASword( $itemNum )
 { {
Line 63: Line 79:
  return( 0 )  return( 0 )
 } }
-</codedoc>+</code>
  
 This example function would be called from another part of your script like this: This example function would be called from another part of your script like this:
-<codedoc>+<code>
   $isSword = IsItemASword( $gTaskItem1 )   $isSword = IsItemASword( $gTaskItem1 )
-</codedoc>+</code>
  
 Functions can have any number of parameters, and always return a value. Functions can have any number of parameters, and always return a value.
Line 80: Line 96:
 A custom event is defined as shown: A custom event is defined as shown:
  
-<codedoc>+<code>
    Event( "Custom", "YourCustomEventName" )    Event( "Custom", "YourCustomEventName" )
    {    {
       *say My Custom Event has been triggered for %PLAYER%       *say My Custom Event has been triggered for %PLAYER%
    }    }
-</codedoc>+</code>
  
 This custom event can be triggered using the command ''*event'' or ''*eventallonline'' (''*eao'' for short). e.g. This custom event can be triggered using the command ''*event'' or ''*eventallonline'' (''*eao'' for short). e.g.
-<codedoc>+<code>
    *event Bob YourCustomEventName    *event Bob YourCustomEventName
-</codedoc>+</code>
 would display ''My Custom Event has been triggered for Bob''. would display ''My Custom Event has been triggered for Bob''.
  
scripting/other_language_features.1580255404.txt.gz · Last modified: 2020/01/28 17:50 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki