Eval Script: Difference between revisions

From HLKitWiki
Jump to navigationJump to search
New page: {{context|Kit Reference|Script Types}} ==Technical Details== :{| class="scripttable" |class="leftnormal"|Initial Context: |Pick |- |Alternate Context: |None |- |Fields F...
 
 
(2 intermediate revisions by the same user not shown)
Line 12: Line 12:
|Fields Finalized?
|Fields Finalized?
|No
|No
|-
|Where Used:
|[[Component Element (Data)|Components]], [[Thing Element (Data)|Things]]
|-
|Procedure Use:
|"eval" type, "pick" context
|-
|-
|}
|}
Line 37: Line 43:
==Example==
==Example==


Every statblock starts with the character's name and then continues with other appropriate information that depends on the game system. The example below shows the start of a Synthesize script that includes the name, race, and age of the character.
Due to the wide range of behaviors that can be applied via Eval scripts, there is no one good example. The XML below shows three separate Eval scripts that are defined as part of the basic handling of equipment within the Sample data files. Each script is scheduled to be performed at a different time during the overall evaluation cycle, with the timing ensuring that each behavior is properly interleaved with other behaviors triggered by other objects.


<pre>
<pre>
var txt as string
<!-- All melee weapons get the appropriate tag -->
<eval index="1" phase="Setup" priority="5000"><![CDATA[
  perform assign[Armory.Melee]
  ]]></eval>


~start by getting our name
<!-- Calculate the net attack roll for the weapon -->
if (empty(hero.actorname) = 0) then
<eval index="2" phase="Final" priority="7000" name="Calc wpNetAtk"><![CDATA[
   txt = hero.actorname
   field[wpNetAtk].value = #trait[skMelee] + field[wpBonus].value + field[wpPenalty].value
else
   ]]></eval>
  txt = "Unnamed Character"
   endif


~output our name
<!-- Prepend any derived special notes to the appropriate field -->
append @boldon & "Name: " & @boldoff & txt & @newline
<eval index="3" phase="Render" priority="2000"><![CDATA[
  var special as string


~output any race
  ~assign any appropriate special notes to the "special" variable here
txt = hero.firstchild["Race.?"].field[name].text
if (empty(txt) <> 0) then
  txt = "-none-"
  endif
append @boldon & "Race: " & @boldoff & txt & @newline


~output age
  ~prepend any existing special details with the notes for this weapon
append @boldon & "Age: " & @boldoff & hero.child[mscPerson].field[perAge].text & @newline
  if (empty(special) = 0) then
    if (field[wpNotes].isempty = 0) then
      special &= ", "
      endif
    field[wpNotes].text = special & field[wpNotes].text
    endif
  ]]></eval>
</pre>
</pre>

Latest revision as of 08:40, 20 February 2009

Context: HL Kit &#133; Kit Reference &#133; Script Types 

Technical Details

Initial Context: Pick
Alternate Context: None
Fields Finalized? No
Where Used: Components, Things
Procedure Use: "eval" type, "pick" context

The Eval script utilizes the following special symbols:

-None- There are no special symbols for an Eval script.

Description

The Eval script is the primary workhorse throughout any set of data files. This script is scheduled within the evaluation cycle and where you will orchestrate the virtually all of the effects for the game system. If a special ability confers a bonus to certain skills, you'll use an Eval script to apply them. If attributes confer adjustments to abilities, attacks, damage, or anything else, you'll use Eval scripts to apply them. Calculated abilities, such as attack ratings or casting powers will be determined through Eval scripts. The list is endless.

Every Eval script is associated with a particular thing. If an Eval script is defined for component, then it is inherited by the things which derive from that component. When a thing is added to a container, it becomes a pick, and new instances of every Eval script for that thing are created and managed by HL. You associate all of the primary behaviors with each pick via the Eval scripts defined for the underlying thing.

When invoked, an Eval script starts with its associated pick as its initial context. You are free to navigate through the hierarchy and effect changes anywhere you deem appropriate. However, all of the changes will typically either be made to the associated pick or be made to other objects based on facets of the associated pick.

As a general rule, all of the dynamic effects that are applied throughout your data files should be handled via Eval scripts. Because the timing of all Eval scripts is controlled, you can ensure that all of the different effects of different scripts are applied in a carefully defined sequence. For example, in the d20 System, adjustments to attributes (e.g. from magic items) must be applied before the bonuses conferred by attributes are calculated and applied.

Eval scripts provide a single, generalized mechanism through which you can accomplish just about anything. As a result, the actual behaviors of an Eval script will vary more widely than with any other type of script. If there is one type of script to get comfortable with first, it is definitely the Eval script.

Example

Due to the wide range of behaviors that can be applied via Eval scripts, there is no one good example. The XML below shows three separate Eval scripts that are defined as part of the basic handling of equipment within the Sample data files. Each script is scheduled to be performed at a different time during the overall evaluation cycle, with the timing ensuring that each behavior is properly interleaved with other behaviors triggered by other objects.

<!-- All melee weapons get the appropriate tag -->
<eval index="1" phase="Setup" priority="5000"><![CDATA[
  perform assign[Armory.Melee]
  ]]></eval>

<!-- Calculate the net attack roll for the weapon -->
<eval index="2" phase="Final" priority="7000" name="Calc wpNetAtk"><![CDATA[
  field[wpNetAtk].value = #trait[skMelee] + field[wpBonus].value + field[wpPenalty].value
  ]]></eval>

<!-- Prepend any derived special notes to the appropriate field -->
<eval index="3" phase="Render" priority="2000"><![CDATA[
  var special as string

  ~assign any appropriate special notes to the "special" variable here

  ~prepend any existing special details with the notes for this weapon
  if (empty(special) = 0) then
    if (field[wpNotes].isempty = 0) then
      special &= ", "
      endif
    field[wpNotes].text = special & field[wpNotes].text
    endif
  ]]></eval>