<li><aclass="backlink"title="Click to do a full-text search for this title"href="./Floats%2C_Definevec4%2C_and_NamedEvents?action=fullsearch&value=linkto%3A%22Floats%2C+Definevec4%2C+and+NamedEvents%22&context=180">Floats, Definevec4, and NamedEvents</a></li>
<spanclass="anchor"id="line-1"></span><pclass="line862">The Desktop can contain information and definitions that are referenced throughout the GUI (and also information that can be referenced outside of the GUI by the game code). <strong>Floats</strong> are values that are often used in if statements as checks. <strong>Definevec4</strong> defines a 4-component value (a color or a size value) and gives it a name that’s easier to reference throughout the GUI. <strong>namedEvent</strong> defines a set of actions to be performed when the namedEvent is referenced in a script or from the GUI itself. <spanclass="anchor"id="line-2"></span><spanclass="anchor"id="line-3"></span><pclass="line862">Finally, the desktop will usually also contain two other scripts: <strong>onInit</strong> and <strong>onESC</strong>. Both of these define actions to happen when the GUI is loaded and when it is closed, respectively. <spanclass="anchor"id="line-4"></span><spanclass="anchor"id="line-5"></span><pclass="line867">
<h3id="head-c862ad59e39e94e213d61f9db16c520491ce4d70">Floats and Definevec4</h3>
<spanclass="anchor"id="line-6"></span><pclass="line867"><hr/><pclass="line874"><spanclass="anchor"id="line-7"></span>The syntax for these items are as follows: <spanclass="anchor"id="line-8"></span><spanclass="anchor"id="line-9"></span><ul><listyle="list-style-type:none"><pclass="line891"><strong>float “valuename” “0”</strong><spanclass="anchor"id="line-10"></span><spanclass="anchor"id="line-11"></span></li></ul><pclass="line874">This defines a variable named valuename and sets it to 0. <spanclass="anchor"id="line-12"></span><spanclass="anchor"id="line-13"></span><ul><listyle="list-style-type:none"><pclass="line891"><strong>definevec4 “yellowtext” “1,1,0,1”</strong><spanclass="anchor"id="line-14"></span><spanclass="anchor"id="line-15"></span></li></ul><pclass="line862">This defines a vec4 called “yellowtext” and sets its RGB + Alpha value to 1,1,0,1. This is extremely usefull when <ahref="#definevec4">used in conjunction with transitions</a> as it allows transitions to reference colors specified as a float rather than hard coded values. If you have a bunch of places you want to transition a color and decide later that you want to change this color, you only have to adjust the desktop float rather than every single place in your onTime animation. <spanclass="anchor"id="line-16"></span><spanclass="anchor"id="line-17"></span><pclass="line867"><spanclass="anchor"id="namedevent"></span><spanclass="anchor"id="line-18"></span>
<spanclass="anchor"id="line-19"></span><pclass="line867"><hr/><pclass="line874"><spanclass="anchor"id="line-20"></span>The syntax for this command is identical to all other scripting functions. namedEvents are usually defined after the floats and vec4s in the Desktop using the <strong>onNamedEvent</strong> function, but they can also be placed in any <ahref="./Def_Types.html">windowDef</a> in the GUI. When the <strong>namedEvent</strong> command is used (either by the GUI itself or from code), it the statements in the corresponding <strong>onNamedEvent</strong> function are executed. <spanclass="anchor"id="line-21"></span><spanclass="anchor"id="line-22"></span><pclass="line874">The following is a named event defined in the Desktop that sets a windowDef's backcolor: <spanclass="anchor"id="line-23"></span><spanclass="anchor"id="line-24"></span><pclass="line867"><spanclass="anchor"id="line-25"></span><pre> onNamedEvent SetBackcolor
<spanclass="anchor"id="line-29"></span></pre><spanclass="anchor"id="line-30"></span><spanclass="anchor"id="line-31"></span><pclass="line862">The following example sends the command to execute that named event when the player selects the <ahref="./Def_Types.html">windowDef</a>: <spanclass="anchor"id="line-32"></span><spanclass="anchor"id="line-33"></span><pclass="line867"><spanclass="anchor"id="line-34"></span><pre> windowDef foo2
<spanclass="anchor"id="line-44"></span></pre><spanclass="anchor"id="line-45"></span><spanclass="anchor"id="line-46"></span><pclass="line862">The following example does the same thing, but references a named event that is defined in the <ahref="./Def_Types.html">windowDef</a> named "foo3" and not in the Desktop: <spanclass="anchor"id="line-47"></span><spanclass="anchor"id="line-48"></span><pclass="line867"><spanclass="anchor"id="line-49"></span><pre> windowDef foo2
<spanclass="anchor"id="line-62"></span><pclass="line867"><hr/><pclass="line874"><spanclass="anchor"id="line-63"></span><strong>Floats</strong>, <strong>vec4s</strong>, <strong>namedEvents</strong>, and <strong>onInit</strong> and <strong>onESC</strong> are defined in the Desktop just as other scripts are for other <ahref="./Def_Types.html">windowDefs</a>– hit <strong>ctrl + Enter</strong> to bring up the scripting window and enter them in. The following would be an example Desktop script. Note that the values defined at the top of the Desktop do not end with a semicolon as all other scripting commands do. <spanclass="anchor"id="line-64"></span><spanclass="anchor"id="line-65"></span><pclass="line867"><spanclass="anchor"id="line-66"></span><pre> definevec4 “yellowtext_on” “1,1,0,1”
<h3id="head-1c138e69b755291b2fd8efc6334962c31fbdb3d4">Referencing Vec4s and Floats</h3>
<spanclass="anchor"id="line-88"></span><pclass="line867"><hr/><pclass="line874"><spanclass="anchor"id="line-89"></span>Referencing floats defined in the Desktop is very simple. If statements often use floats to choose when to perform other actions: <spanclass="anchor"id="line-90"></span><spanclass="anchor"id="line-91"></span><pclass="line867"><spanclass="anchor"id="line-92"></span><pre> if (“desktop::check1” == 0) {
<spanclass="anchor"id="line-93"></span> // performs an action
<spanclass="anchor"id="line-94"></span> }
<spanclass="anchor"id="line-95"></span></pre><spanclass="anchor"id="line-96"></span><spanclass="anchor"id="line-97"></span><pclass="line874">Floats can also be changed using the set command: <spanclass="anchor"id="line-98"></span><spanclass="anchor"id="line-99"></span><pclass="line867"><spanclass="anchor"id="line-100"></span><pre> set “desktop::check1” “1” ;
<spanclass="anchor"id="line-101"></span></pre><spanclass="anchor"id="line-102"></span><spanclass="anchor"id="line-103"></span><pclass="line867"><spanclass="anchor"id="definevec4"></span><spanclass="anchor"id="line-104"></span>The syntax for using vec4s is slightly different, but straightforward. The following example uses the “yellowtext_on” and “yellowtext_off” vec4s we defined in our example Desktop script: <spanclass="anchor"id="line-105"></span><spanclass="anchor"id="line-106"></span><pclass="line867"><spanclass="anchor"id="line-107"></span><pre> transition “button1::forecolor” “$desktop::yellowtext_off” “$desktop::yellowtext_on” “200” ;
<li><ahref="http://moinmoin.wikiwikiweb.de/">MoinMoin Powered</a></li><li><ahref="http://www.python.org/">Python Powered</a></li><li><ahref="http://validator.w3.org/check?uri=referer">Valid HTML 4.01</a></li>