Difference between revisions of "Script Compiler Override"

47 bytes removed ,  09:53, 16 February 2015
m
imported>Odessa
imported>Odessa
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Overview==
==Overview==
If using [[Let]], [[Eval|if eval]], [[While]], and some other new NVSE functions, it is permitted to pass [[Array Variable|array elements]], [[String Variable|string variables]] and [[User Defined Function|(perhaps user defined)]] nested function calls directly as parameters. However, the vanilla script compiler will prohibit direct passage to vanilla and older NVSE functions, complaining that the paramater type is invalid (it isn't sure what type the array element or function return will be, since it could potentially be any). Typically, this forces you to use an intermediary variable. Alternatively, the script compiler override (CO) allows you to ignore these 'misgivings', and assuming that you know the types are safe, compile scripts that will work correctly.  
If using [[Let]], [[Eval|if eval]], [[While]], [[Print]] and some other new NVSE functions, it is permitted to pass [[Array Variable|array elements]], [[String Variable|string variables]] and [[User Defined Function|(perhaps user defined)]] nested function calls directly as parameters. However, the vanilla script compiler will prohibit direct passage to vanilla and older NVSE functions, complaining that the paramater type is invalid (it isn't sure what type the array element or function return will be, since it could potentially be any). Typically, this forces you to use an intermediary variable. Alternatively, the script compiler override (CO) allows you to ignore these 'misgivings', and assuming that you know the types are safe, compile scripts that will work correctly.  


To use the CO, you prefix a script block type with an underscore (eg: <b>Begin _GameMode</b>). See the following examples for further details, and also the warning at the end of this article.
To use the CO, you prefix a script block type with an underscore (eg: <b>Begin _GameMode</b>). See the following examples for further details, and also the warning at the end of this article.
 
==Example #1==
==Example #1==
Let's say we have a number that we want to get the [[Floor]] of, the nearest whole number lower than the float. The vanilla compiler will know what we want to do if we specify it as a float variable that we pass to the floor function as a parameter:
Let's say we have a number that we want to get the [[Floor]] of, the nearest whole number lower than the float. The vanilla compiler will know what we want to do if we specify it as a float variable that we pass to the floor function as a parameter:
Line 124: Line 124:
</pre>
</pre>


You can refer to the actor value by its code number, which you can find at the bottom of the woefully outdated nvse (read: fose) docs:
You can refer to the actor value by its [[Actor Value Codes|code number]]:
<pre>
<pre>
let fHealth := rActor.GetAV 16
let fHealth := rActor.GetAV 16
Line 172: Line 172:
int iCount
int iCount
int iChoice
int iChoice
int iCondition
float fCondition
ref rItem
ref rItem


Line 179: Line 179:
   let iChoice := Rand 0, iCount
   let iChoice := Rand 0, iCount
   let rItem := ListGetNthForm SomeFormList, iChoice
   let rItem := ListGetNthForm SomeFormList, iChoice
   let iCondition := Rand 0, 1
   let fCondition := Rand 0, 1
   PlayerREF.AddItemHealthPercent rItem, 1, iCondition
   PlayerREF.AddItemHealthPercent rItem, 1, fCondition
End
End
</pre>
</pre>
Line 187: Line 187:
<pre>
<pre>
Begin _GameMode
Begin _GameMode
     PlayerREF.AddItemHealthPercent (ListGetNthForm SomeFormList, (Rand 0, (ListGetCount SomeFormList), 1, (Rand 0, 1)
     PlayerREF.AddItemHealthPercent (ListGetNthForm SomeFormList, (Rand 0, (ListGetCount SomeFormList))), 1, (Rand 0, 1)
End
End
</pre>
</pre>
Anonymous user