mirror of
https://github.com/dhewm/iddevnet.git
synced 2024-11-24 13:21:46 +00:00
ee11625497
https://web.archive.org/web/*/http://iddevnet.com/quake4/* had them even though the links in the corresponding archived pages didn't work
373 lines
43 KiB
HTML
373 lines
43 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||
<meta name="robots" content="index,nofollow">
|
||
|
||
<title>BasicScriptTutorial - Quake 4 SDK Documentation</title>
|
||
<script type="text/javascript" src="wiki/common/js/common.js"></script>
|
||
|
||
<script type="text/javascript">
|
||
<!--// common functions
|
||
|
||
// We keep here the state of the search box
|
||
searchIsDisabled = false;
|
||
|
||
function searchChange(e) {
|
||
// Update search buttons status according to search box content.
|
||
// Ignore empty or whitespace search term.
|
||
var value = e.value.replace(/\s+/, '');
|
||
if (value == '' || searchIsDisabled) {
|
||
searchSetDisabled(true);
|
||
} else {
|
||
searchSetDisabled(false);
|
||
}
|
||
}
|
||
|
||
function searchSetDisabled(flag) {
|
||
// Enable or disable search
|
||
document.getElementById('fullsearch').disabled = flag;
|
||
document.getElementById('titlesearch').disabled = flag;
|
||
}
|
||
|
||
function searchFocus(e) {
|
||
// Update search input content on focus
|
||
if (e.value == 'Search') {
|
||
e.value = '';
|
||
e.className = '';
|
||
searchIsDisabled = false;
|
||
}
|
||
}
|
||
|
||
function searchBlur(e) {
|
||
// Update search input content on blur
|
||
if (e.value == '') {
|
||
e.value = 'Search';
|
||
e.className = 'disabled';
|
||
searchIsDisabled = true;
|
||
}
|
||
}
|
||
|
||
function actionsMenuInit(title) {
|
||
// Initialize action menu
|
||
for (i = 0; i < document.forms.length; i++) {
|
||
var form = document.forms[i];
|
||
if (form.className == 'actionsmenu') {
|
||
// Check if this form needs update
|
||
var div = form.getElementsByTagName('div')[0];
|
||
var label = div.getElementsByTagName('label')[0];
|
||
if (label) {
|
||
// This is the first time: remove label and do buton.
|
||
div.removeChild(label);
|
||
var dobutton = div.getElementsByTagName('input')[0];
|
||
div.removeChild(dobutton);
|
||
// and add menu title
|
||
var select = div.getElementsByTagName('select')[0];
|
||
var item = document.createElement('option');
|
||
item.appendChild(document.createTextNode(title));
|
||
item.value = 'show';
|
||
select.insertBefore(item, select.options[0]);
|
||
select.selectedIndex = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//-->
|
||
</script>
|
||
|
||
|
||
<link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="wiki/modern/css/common.css">
|
||
<link rel="stylesheet" type="text/css" charset="utf-8" media="screen" href="wiki/modern/css/screen.css">
|
||
<link rel="stylesheet" type="text/css" charset="utf-8" media="print" href="wiki/modern/css/print.css">
|
||
<link rel="stylesheet" type="text/css" charset="utf-8" media="projection" href="wiki/modern/css/projection.css">
|
||
|
||
<!-- css only for MSIE browsers -->
|
||
<!--[if IE]>
|
||
<link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="wiki/modern/css/msie.css">
|
||
<![endif]-->
|
||
|
||
|
||
|
||
<link rel="Start" href="./Quake4SDK.html">
|
||
<link rel="Alternate" title="Wiki Markup" href="./BasicScriptTutorial?action=raw">
|
||
<link rel="Alternate" media="print" title="Print View" href="./BasicScriptTutorial?action=print">
|
||
<link rel="Appendix" title="basicscripttutorial1.png" href="./BasicScriptTutorial?action=AttachFile&do=view&target=basicscripttutorial1.png">
|
||
<link rel="Appendix" title="basicscripttutorial2.png" href="./BasicScriptTutorial?action=AttachFile&do=view&target=basicscripttutorial2.png">
|
||
<link rel="Appendix" title="basicscripttutorial3.png" href="./BasicScriptTutorial?action=AttachFile&do=view&target=basicscripttutorial3.png">
|
||
<link rel="Appendix" title="basicscripttutorial4.png" href="./BasicScriptTutorial?action=AttachFile&do=view&target=basicscripttutorial4.png">
|
||
<link rel="Appendix" title="basicscripttutorial5.png" href="./BasicScriptTutorial?action=AttachFile&do=view&target=basicscripttutorial5.png">
|
||
<link rel="Appendix" title="basicscripttutorial6.png" href="./BasicScriptTutorial?action=AttachFile&do=view&target=basicscripttutorial6.png">
|
||
<link rel="Appendix" title="basicscripttutorial7.png" href="./BasicScriptTutorial?action=AttachFile&do=view&target=basicscripttutorial7.png">
|
||
<link rel="Search" href="./FindPage.html">
|
||
<link rel="Index" href="./TitleIndex.html">
|
||
<link rel="Glossary" href="./WordIndex.html">
|
||
<link rel="Help" href="./HelpOnFormatting.html">
|
||
</head>
|
||
|
||
<body lang="en" dir="ltr">
|
||
|
||
<div id="header">
|
||
<div id="logo"><a href="./Quake4SDK.html"><img src="wiki/common/moinmoin.png" alt="MoinMoin Logo"></a></div>
|
||
|
||
<form id="searchform" method="get" action="">
|
||
<div>
|
||
<input type="hidden" name="action" value="fullsearch">
|
||
<input type="hidden" name="context" value="180">
|
||
<label for="searchinput">Search:</label>
|
||
<input id="searchinput" type="text" name="value" value="" size="20"
|
||
onfocus="searchFocus(this)" onblur="searchBlur(this)"
|
||
onkeyup="searchChange(this)" onchange="searchChange(this)" alt="Search">
|
||
<input id="titlesearch" name="titlesearch" type="submit"
|
||
value="Titles" alt="Search Titles">
|
||
<input id="fullsearch" name="fullsearch" type="submit"
|
||
value="Text" alt="Search Full Text">
|
||
</div>
|
||
</form>
|
||
<script type="text/javascript">
|
||
<!--// Initialize search form
|
||
var f = document.getElementById('searchform');
|
||
f.getElementsByTagName('label')[0].style.display = 'none';
|
||
var e = document.getElementById('searchinput');
|
||
searchChange(e);
|
||
searchBlur(e);
|
||
//-->
|
||
</script>
|
||
|
||
<ul id="username"><li><a href="./BasicScriptTutorial?action=login" id="login">Login</a></li></ul>
|
||
<div id="locationline">
|
||
|
||
|
||
<ul id="pagelocation">
|
||
<li><a class="backlink" title="Click to do a full-text search for this title" href="./BasicScriptTutorial?action=fullsearch&value=linkto%3A%22BasicScriptTutorial%22&context=180">BasicScriptTutorial</a></li>
|
||
</ul>
|
||
|
||
</div>
|
||
|
||
|
||
<ul id="navibar">
|
||
<li class="wikilink"><a href="./GettingStarted.html">GettingStarted</a></li><li class="wikilink"><a href="./ScriptFile.html">ScriptFile</a></li><li class="wikilink"><a href="./MakeAMod.html">MakeAMod</a></li><li class="wikilink"><a href="./LevelEditor.html">LevelEditor</a></li><li class="wikilink"><a href="./FXEditor.html">FXEditor</a></li><li class="wikilink"><a href="./GUIEditor.html">GUIEditor</a></li><li class="wikilink"><a href="./Sounds.html">Sounds</a></li><li class="wikilink"><a href="./Animations.html">Animations</a></li><li class="wikilink"><a href="./ArtReference.html">ArtReference</a></li><li class="wikilink"><a href="./DownloadableContent.html">DownloadableContent</a></li><li class="wikilink"><a href="./RecentChanges.html">RecentChanges</a></li><li class="wikilink"><a href="./FindPage.html">FindPage</a></li><li class="wikilink"><a href="./HelpContents.html">HelpContents</a></li><li class="current"><a href="./BasicScriptTutorial.html">BasicScriptTutorial</a></li>
|
||
</ul>
|
||
|
||
<div id="pageline"><hr style="display:none;"></div>
|
||
|
||
<ul class="editbar"><li><span class="disabled">Immutable Page</span></li><li><a href="./BasicScriptTutorial?action=info">Info</a></li><li><a href="./BasicScriptTutorial?action=AttachFile">Attachments</a></li><li>
|
||
<form class="actionsmenu" method="get" action="">
|
||
<div>
|
||
<label>More Actions:</label>
|
||
<select name="action"
|
||
onchange="if ((this.selectedIndex != 0) &&
|
||
(this.options[this.selectedIndex].disabled == false)) {
|
||
this.form.submit();
|
||
}
|
||
this.selectedIndex = 0;">
|
||
<option value="raw">Raw Text</option>
|
||
<option value="print">Print View</option>
|
||
<option value="RenderAsDocbook">Render as Docbook</option>
|
||
<option value="refresh">Delete Cache</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="SpellCheck">Check Spelling</option>
|
||
<option value="LikePages">Like Pages</option>
|
||
<option value="LocalSiteMap">Local Site Map</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="RenamePage" disabled class="disabled">Rename Page</option>
|
||
<option value="DeletePage" disabled class="disabled">Delete Page</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="MyPages">My Pages</option>
|
||
<option value="SubscribeUser">Subscribe User</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="Despam">Remove Spam</option>
|
||
<option value="PackagePages">Package Pages</option>
|
||
</select>
|
||
<input type="submit" value="Do">
|
||
</div>
|
||
<script type="text/javascript">
|
||
<!--// Init menu
|
||
actionsMenuInit('More Actions:');
|
||
//-->
|
||
</script>
|
||
</form>
|
||
</li></ul>
|
||
|
||
</div>
|
||
|
||
<div id="page" lang="en" dir="ltr">
|
||
<div dir="ltr" id="content" lang="en"><span class="anchor" id="top"></span>
|
||
<span class="anchor" id="line-1"></span><p class="line867"><img alt="/!\" height="15" src="wiki/modern/img/alert.png" title="/!\" width="15" /> <strong>This page still under development</strong> <span class="anchor" id="line-2"></span><span class="anchor" id="line-3"></span><p class="line874">The Quake 4 Script system is a powerful method of creating exciting content for your mod. Much like the special entities you can place in a map to create different effects, the script system contains all sorts of tools to control nearly every aspect of all game entities. <span class="anchor" id="line-4"></span><span class="anchor" id="line-5"></span><p class="line874">From gripping cinematics to run and gun boss battles, the script system allows you to add spice and flavor to the standard behavior of Quake 4’s entities. Used in conjunction with map entities and game code, you can create all new game types! <span class="anchor" id="line-6"></span><span class="anchor" id="line-7"></span><p class="line874">Many pages could be dedicated to the similarities and contrasts between using script to create gameplay and using map entities, but we won’t do that here. Use this tutorial to unearth the power of scripting, then draw your own conclusions. <span class="anchor" id="line-8"></span><span class="anchor" id="line-9"></span><p class="line867">
|
||
<h1 id="head-7b46b3928c84f10d349092242d1dcd5a6ecc54c9">What You’ll Need</h1>
|
||
<span class="anchor" id="line-10"></span><span class="anchor" id="line-11"></span><p class="line874">You will need a licensed copy of Quake 4 and the SDK. You will be using both the map editor, and a script editing tool of your choice. <span class="anchor" id="line-12"></span><span class="anchor" id="line-13"></span><p class="line874">Script editing can be done in any text editing program. However, since the script system closely resembles C style code, an editor that uses syntax highlighting would be best. Our developers here used both Visual Studio and Ultra Edit 32, but in a pinch you can use notepad.exe. <span class="anchor" id="line-14"></span><span class="anchor" id="line-15"></span><p class="line867"><span class="anchor" id="savemap"></span> <span class="anchor" id="line-16"></span>
|
||
<h1 id="head-5337f61f6ae189ba2205c9d73ef4b7cb773d1169">Setting up your first script file</h1>
|
||
<span class="anchor" id="line-17"></span><span class="anchor" id="line-18"></span><p class="line874">Script files can be set up two ways. One method is for quick practice and “scratchpad” style development, the other is for distribution. To get started, we’ll use the first method because it’s much simpler. Create a new text file in the directory that has the .map file you want to use the script on. For example, if you’re working out of C:\Program Files\Quake4\q4base\maps\, you’d place the file there. <span class="anchor" id="line-19"></span><span class="anchor" id="line-20"></span><p class="line867"><img class="attachment" src="basicscripttutorial1.png" title="attachment:basicscripttutorial1.png" /> <span class="anchor" id="line-21"></span><span class="anchor" id="line-22"></span><p class="line874">Name the file [mapname].script. So if your map is called “awesome.map” you’d name the file “awesome.script” <span class="anchor" id="line-23"></span><span class="anchor" id="line-24"></span><p class="line867"><img class="attachment" src="basicscripttutorial2.png" title="attachment:basicscripttutorial2.png" /> <span class="anchor" id="line-25"></span><span class="anchor" id="line-26"></span><p class="line867">
|
||
<h1 id="head-570f051b69d313da23334cefad6e29530ae2ae75">Your first script function, “Hello Stroggos”</h1>
|
||
<span class="anchor" id="line-27"></span><span class="anchor" id="line-28"></span><p class="line874">Open up the script file you just created with your editor. Enter the following into the file and save the file. <span class="anchor" id="line-29"></span><span class="anchor" id="line-30"></span><p class="line867"><span class="anchor" id="line-31"></span><span class="anchor" id="line-32"></span><span class="anchor" id="line-33"></span><span class="anchor" id="line-34"></span><span class="anchor" id="line-35"></span><span class="anchor" id="line-36"></span><span class="anchor" id="line-37"></span><div class="codearea" dir="ltr" lang="en">
|
||
<script type="text/javascript">
|
||
function isnumbered(obj) {
|
||
return obj.childNodes.length && obj.firstChild.childNodes.length && obj.firstChild.firstChild.className == 'LineNumber';
|
||
}
|
||
function nformat(num,chrs,add) {
|
||
var nlen = Math.max(0,chrs-(''+num).length), res = '';
|
||
while (nlen>0) { res += ' '; nlen-- }
|
||
return res+num+add;
|
||
}
|
||
function addnumber(did, nstart, nstep) {
|
||
var c = document.getElementById(did), l = c.firstChild, n = 1;
|
||
if (!isnumbered(c))
|
||
if (typeof nstart == 'undefined') nstart = 1;
|
||
if (typeof nstep == 'undefined') nstep = 1;
|
||
n = nstart;
|
||
while (l != null) {
|
||
if (l.tagName == 'SPAN') {
|
||
var s = document.createElement('SPAN');
|
||
s.className = 'LineNumber'
|
||
s.appendChild(document.createTextNode(nformat(n,4,' ')));
|
||
n += nstep;
|
||
if (l.childNodes.length)
|
||
l.insertBefore(s, l.firstChild)
|
||
else
|
||
l.appendChild(s)
|
||
}
|
||
l = l.nextSibling;
|
||
}
|
||
return false;
|
||
}
|
||
function remnumber(did) {
|
||
var c = document.getElementById(did), l = c.firstChild;
|
||
if (isnumbered(c))
|
||
while (l != null) {
|
||
if (l.tagName == 'SPAN' && l.firstChild.className == 'LineNumber') l.removeChild(l.firstChild);
|
||
l = l.nextSibling;
|
||
}
|
||
return false;
|
||
}
|
||
function togglenumber(did, nstart, nstep) {
|
||
var c = document.getElementById(did);
|
||
if (isnumbered(c)) {
|
||
remnumber(did);
|
||
} else {
|
||
addnumber(did,nstart,nstep);
|
||
}
|
||
return false;
|
||
}
|
||
</script>
|
||
|
||
<script type="text/javascript">
|
||
document.write('<a href="#" onclick="return togglenumber(\'CA-76aa8bb98bcc8c40c11e3dadd02858f43f588132_000\', 1, 1);" \
|
||
class="codenumbers">Toggle line numbers<\/a>');
|
||
</script>
|
||
<pre dir="ltr" id="CA-76aa8bb98bcc8c40c11e3dadd02858f43f588132_000" lang="en"><span class="line"><span class="LineNumber"> 1 </span><span class="ResWord">void</span> <span class="ID">HelloStroggos</span><span class="SPChar">(</span><span class="SPChar">)</span> <span class="SPChar">{</span></span>
|
||
<span class="line"><span class="LineNumber"> 2 </span></span>
|
||
<span class="line"><span class="LineNumber"> 3 </span> <span class="Comment">//speak to the world</span></span>
|
||
<span class="line"><span class="LineNumber"> 4 </span> <span class="ID">sys</span><span class="SPChar">.</span><span class="ID">println</span><span class="SPChar">(</span>“<span class="ID">Hello</span> <span class="ID">Stroggos</span><span class="SPChar">!</span>”<span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 5 </span></span>
|
||
<span class="line"><span class="LineNumber"> 6 </span><span class="SPChar">}</span></span>
|
||
</pre></div><span class="anchor" id="line-38"></span><p class="line874">If you’re not familiar with C-style programming, that all looks like a lot of jive. If you are familiar, go ahead and skip to the next header because this is probably old hat to you. <span class="anchor" id="line-39"></span><span class="anchor" id="line-40"></span><p class="line874">What you just wrote is called a function. Functions are called from the map by triggers—something we’ll get into later. Functions can also be called by other functions, but that’s getting way ahead. Let’s break it down. <span class="anchor" id="line-41"></span><span class="anchor" id="line-42"></span><p class="line862">The <strong>void</strong> is the <em>return type</em>, this is what a function gives back to you when it’s done. This function doesn’t give anything back, so we use the word “void” to represent that. <span class="anchor" id="line-43"></span><span class="anchor" id="line-44"></span><p class="line862">The next part is the <em>function name</em>. The <strong>()</strong> at the end are where 'parameters' go. If we need to send data to a function, we do it with parameters. Right now, we don’t need any, so the parentheses are empty. <span class="anchor" id="line-45"></span><span class="anchor" id="line-46"></span><p class="line862">You’ll notice the entire function is wrapped in squirrely braces, these right here: <strong>{ }</strong> This is a must. If you forget them, even one of them, your stuff won’t work. <span class="anchor" id="line-47"></span><span class="anchor" id="line-48"></span><p class="line862">The next line, the one with the <strong>//</strong> slashes, is a <em>comment</em>. Comments are just for us, the compiler never sees them. You can write whatever you’d like in a comment. They are not mandatory, but good comments help you remember just what you were doing in a function. <span class="anchor" id="line-49"></span><span class="anchor" id="line-50"></span><p class="line862">Finally we get to the meat. This line calls a function from the <a href="./SystemObject.html">SystemObject</a>, called "<a href="./SystemObject.html">sys</a>.” <a href="./SystemObject.html">Sys</a> represents the game system, and can do quite a lot for us, which you’ll see later. Right now, <a href="./SystemObject.html">sys</a> is using the Print Line function, <a href="./ScriptFunction_println.html">println</a>. <a href="./ScriptFunction_println.html">println</a> takes in one parameter, which is a line of text that you wanted printed to the console. It’s very simple. <span class="anchor" id="line-51"></span><span class="anchor" id="line-52"></span><p class="line874">Notice that the line ends with a semicolon! Semicolons are the only way the compiler knows to stop reading commands from that line. You must include them at the end of your lines, or your stuff won’t run. Especially during these early steps of learning scripting, nine times out of ten when your scripts don’t compile, you forgot a semicolon. <span class="anchor" id="line-53"></span><span class="anchor" id="line-54"></span><p class="line867">
|
||
<h1 id="head-3fedf63c9d65f948bcaf6720bfabdc12d395d061">Calling your script from game with triggers</h1>
|
||
<span class="anchor" id="line-55"></span><span class="anchor" id="line-56"></span><p class="line862">At this point, you should save and close the script file. Now it’s time to open up the editor. Open up an empty map suitable for gameplay, a room with a light and an <a class="nonexistent" href="./InfoPlayerStart.html">InfoPlayerStart</a>. Create a new brush, right click it and change it to a trigger_once. <span class="anchor" id="line-57"></span><span class="anchor" id="line-58"></span><p class="line867"><img class="attachment" src="basicscripttutorial3.png" title="attachment:basicscripttutorial3.png" /> <span class="anchor" id="line-59"></span><span class="anchor" id="line-60"></span><p class="line874">A trigger is an invisible brush that is activated by certain conditions. Usually this boils down to the player touching it and something happening. In our case, we want the trigger to call a function for us. So let’s set that key value on the entity. <span class="anchor" id="line-61"></span><span class="anchor" id="line-62"></span><p class="line867"><img class="attachment" src="basicscripttutorial4.png" title="attachment:basicscripttutorial4.png" /> <span class="anchor" id="line-63"></span><span class="anchor" id="line-64"></span><p class="line874">Very straightforward. Notice here we don’t have to include the void or parentheses from the script file. Just the name of the function will do for now. <span class="anchor" id="line-65"></span><span class="anchor" id="line-66"></span><p class="line874">That should do it! Save and BSP your map, then run that level in game. If all went well, you should see “Hello Stroggos!” on screen. If you aren’t running in developer mode, or if con_showPrint is set to 0, you’ll have to open the console to see the message. <span class="anchor" id="line-67"></span><span class="anchor" id="line-68"></span><p class="line867"><a href="#compileerror">Did it not work for you?</a> <span class="anchor" id="line-69"></span><span class="anchor" id="line-70"></span><p class="line867">
|
||
<h1 id="head-43415c887998cc4ccee3925483c86646b99e7640">Further Changes to the Script and the Map</h1>
|
||
<span class="anchor" id="line-71"></span><span class="anchor" id="line-72"></span><p class="line874">Now that you've got your script running, let's work a little further. We will modify our script and our map to change things up and spawn in a monster. <span class="anchor" id="line-73"></span><span class="anchor" id="line-74"></span><p class="line862">First, open the editor and add a <a href="./Entity_TargetNull.html">target_null</a> to the map. Place the <a href="./Entity_TargetNull.html">target_null</a> on the map in a place where you'd like the monster to spawn. Remember that monster origins are at the centered at the feet of the monster so place the origin <a href="./Entity_TargetNull.html">target_null</a> even with the ground unless you want the monster to fall out of the sky. <span class="anchor" id="line-75"></span><span class="anchor" id="line-76"></span><p class="line867"><img class="attachment" src="basicscripttutorial5.png" title="attachment:basicscripttutorial5.png" /> <img class="attachment" src="basicscripttutorial6.png" title="attachment:basicscripttutorial6.png" /> <span class="anchor" id="line-77"></span><span class="anchor" id="line-78"></span><p class="line862">Give that <a href="./Entity_TargetNull.html">target_null</a> a name you'll remember. For our example we'll use targetMonster. <span class="anchor" id="line-79"></span><span class="anchor" id="line-80"></span><p class="line874">Go back to your script and add a few lines to the function we wrote earlier. <span class="anchor" id="line-81"></span><span class="anchor" id="line-82"></span><p class="line867"><span class="anchor" id="line-83"></span><span class="anchor" id="line-84"></span><span class="anchor" id="line-85"></span><span class="anchor" id="line-86"></span><span class="anchor" id="line-87"></span><span class="anchor" id="line-88"></span><span class="anchor" id="line-89"></span><span class="anchor" id="line-90"></span><span class="anchor" id="line-91"></span><span class="anchor" id="line-92"></span><span class="anchor" id="line-93"></span><span class="anchor" id="line-94"></span><span class="anchor" id="line-95"></span><span class="anchor" id="line-96"></span><span class="anchor" id="line-97"></span><span class="anchor" id="line-98"></span><span class="anchor" id="line-99"></span><div class="codearea" dir="ltr" lang="en">
|
||
<script type="text/javascript">
|
||
document.write('<a href="#" onclick="return togglenumber(\'CA-de4a9c423b2145d71f13d813d93e3b61349ef9bb_001\', 1, 1);" \
|
||
class="codenumbers">Toggle line numbers<\/a>');
|
||
</script>
|
||
<pre dir="ltr" id="CA-de4a9c423b2145d71f13d813d93e3b61349ef9bb_001" lang="en"><span class="line"><span class="LineNumber"> 1 </span><span class="ResWord">void</span> <span class="ID">HelloStroggos</span><span class="SPChar">(</span><span class="SPChar">)</span> <span class="SPChar">{</span></span>
|
||
<span class="line"><span class="LineNumber"> 2 </span></span>
|
||
<span class="line"><span class="LineNumber"> 3 </span> <span class="Comment">//speak to the world</span></span>
|
||
<span class="line"><span class="LineNumber"> 4 </span> <span class="ID">sys</span><span class="SPChar">.</span><span class="ID">println</span><span class="SPChar">(</span>“<span class="ID">Hello</span> <span class="ID">Stroggos</span><span class="SPChar">!</span>”<span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 5 </span></span>
|
||
<span class="line"><span class="LineNumber"> 6 </span> <span class="Comment">//new steps! ----------------------------------</span></span>
|
||
<span class="line"><span class="LineNumber"> 7 </span></span>
|
||
<span class="line"><span class="LineNumber"> 8 </span> <span class="Comment">//create a variable to hold the entity handle with.</span></span>
|
||
<span class="line"><span class="LineNumber"> 9 </span> <span class="ID">entity</span> <span class="ID">newMonster</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 10 </span></span>
|
||
<span class="line"><span class="LineNumber"> 11 </span> <span class="Comment">//spawn the monster and store his handle in the variable</span></span>
|
||
<span class="line"><span class="LineNumber"> 12 </span> <span class="ID">newMonster</span> <span class="SPChar">=</span> <span class="ID">sys</span><span class="SPChar">.</span><span class="ID">spawn</span><span class="SPChar">(</span><span class="String">"monster_strogg_marine"</span><span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 13 </span></span>
|
||
<span class="line"><span class="LineNumber"> 14 </span> <span class="Comment">//move him to where that new target_null lives</span></span>
|
||
<span class="line"><span class="LineNumber"> 15 </span> <span class="ID">newMonster</span><span class="SPChar">.</span><span class="ID">setWorldOrigin</span><span class="SPChar">(</span> $<span class="ID">targetMonster</span><span class="SPChar">.</span><span class="ID">getWorldOrigin</span><span class="SPChar">(</span><span class="SPChar">)</span> <span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 16 </span><span class="SPChar">}</span></span>
|
||
</pre></div><span class="anchor" id="line-100"></span><span class="anchor" id="line-101"></span><p class="line874">Let's go over this new stuff! <span class="anchor" id="line-102"></span><span class="anchor" id="line-103"></span><p class="line867"><strong><tt class="backtick">entity newMonster</tt></strong> creates a <em><a href="./ScriptVariable.html">variable</a></em> for us of the <em>entity</em> type. A <a href="./ScriptVariable.html">variable</a> is a just a label for a piece of memory. When we spawn in our new creature, we want to have a way to access him later in the script. We use <a href="./ScriptVariable.html">variables</a> to keep track of all sorts of information. <span class="anchor" id="line-104"></span><span class="anchor" id="line-105"></span><p class="line874">Right now newMonster is empty. We're going to spawn in a strogg marine, and store the resulting handle into the newMonster variable. <span class="anchor" id="line-106"></span><span class="anchor" id="line-107"></span><p class="line867"><strong><tt class="backtick">newMonster = sys.spawn("monster_strogg_marine");</tt></strong> does just that! We use the <a href="./ScriptEvent_spawn.html">spawn</a> command to tell the game to create a new entity of whatever type we tell it. Anytime we enter text between quotes, we call it a <a href="./ScriptVariable.html#string">string</a>. That string is the parameter-- you remember those from earlier? So we're telling the game to create us a Strogg Marine, and to put the handle to that Strogg Marine inside our variable called newMonster. <span class="anchor" id="line-108"></span><span class="anchor" id="line-109"></span><p class="line862">At this point, a Strogg Marine is created, but he's been placed at world location 0,0,0. That's no good, we want him to appear at the <a href="./Entity_TargetNull.html">target_null</a> we made earlier! <span class="anchor" id="line-110"></span><span class="anchor" id="line-111"></span><p class="line862">To move an entity to a different position in the map instantly, we use the <a href="./ScriptEvent_SetWorldOrigin.html">setWorldOrigin</a> event. This is an instant move, the entity will pop into position over the course of a single frame. We do that with <strong><tt class="backtick">newMonster.setWorldOrigin( )</tt></strong>. <span class="anchor" id="line-112"></span><span class="anchor" id="line-113"></span><p class="line862">Up until now we've been calling all our functions on the <a href="./SystemObject.html">SystemObject</a>. Functions can be called on all sorts of objects though, the <a href="./SystemObject.html">SystemObject</a> is only the beginning. To learn more about these functions, check out the <a href="./ScriptFile_Events.html">Script Events</a> page. <span class="anchor" id="line-114"></span><span class="anchor" id="line-115"></span><p class="line862">The function <a href="./ScriptEvent_SetWorldOrigin.html">setWorldOrigin</a> needs a parameter though. Let's give it the origin of that <a href="./Entity_TargetNull.html">target_null</a> we made earlier. We can call a function on that <a href="./Entity_TargetNull.html">target_null</a> to get it's origin. So we will. <span class="anchor" id="line-116"></span><span class="anchor" id="line-117"></span><p class="line867"><strong><tt class="backtick">$targetMonster.getWorldOrigin()</tt></strong> returns to us the entity's origin in the world as a <a href="./ScriptVariable.html#vector">vector</a>. The <strong><tt class="backtick">$targetMonster</tt></strong> part is special. We use that $ symbol to reference any entity that is in the map. In this example, we use $targetMonster because that's what we named the <a href="./Entity_TargetNull.html">target_null</a>. If you named yours differently, use that different name. <span class="anchor" id="line-118"></span><span class="anchor" id="line-119"></span><p class="line867"><img alt="/!\" height="15" src="wiki/modern/img/alert.png" title="/!\" width="15" /> This part is important, and a bit confusing at first. <a href="./Tutorial_ScriptEntities.html">Understand the difference between an entity variable and the $ symbol</a>. That link will take you to a more detailed example if you need it. <span class="anchor" id="line-120"></span><span class="anchor" id="line-121"></span><p class="line867"><a href="./ScriptEvent_SetWorldOrigin.html">setWorldOrigin</a> needs a vector as it's parameter, and luckily <a href="./ScriptEvent_GetWorldOrigin.html">getWorldOrigin</a> gives us just that. So this line, <span class="anchor" id="line-122"></span><span class="anchor" id="line-123"></span><p class="line867"><strong><tt class="backtick">newMonster.setWorldOrigin( $targetMonster.getWorldOrigin());</tt></strong> <span class="anchor" id="line-124"></span><span class="anchor" id="line-125"></span><p class="line862">Will place the monster directly on the origin of that <a href="./Entity_TargetNull.html">target_null</a>. <span class="anchor" id="line-126"></span><span class="anchor" id="line-127"></span><p class="line874">Save your script file! <span class="anchor" id="line-128"></span><span class="anchor" id="line-129"></span><p class="line867"><span class="anchor" id="reloadscript"></span> <span class="anchor" id="line-130"></span>
|
||
<h1 id="head-d72083de6b941fe9aebdb41e8eee13646bc977b9">Running the Script Anew</h1>
|
||
<span class="anchor" id="line-131"></span><span class="anchor" id="line-132"></span><p class="line862">Now, if you've closed the game since you've run the Hello Stroggos example, just load it again and this script should work out fine. However, if you've still got the game running from before, you'll need to execute a <a href="./ConsoleCommand_ReloadScript.html">Reload Script</a> command in the console. <span class="anchor" id="line-133"></span><span class="anchor" id="line-134"></span><p class="line862">Once you've saved your script, drop the console in game and enter the command <a href="./ConsoleCommand_ReloadScript.html">reloadScript</a>. The game should pause for a few seconds, then show you this: <span class="anchor" id="line-135"></span><span class="anchor" id="line-136"></span><p class="line867"><span class="anchor" id="line-137"></span><pre>******************************
|
||
<span class="anchor" id="line-138"></span>ERROR: Exiting map to reload scripts
|
||
<span class="anchor" id="line-139"></span>******************************
|
||
<span class="anchor" id="line-140"></span></pre><span class="anchor" id="line-141"></span><span class="anchor" id="line-142"></span><p class="line862">This is perfectly normal, and it means your script compiled fine. But if you see any other errors, head to the <a href="#compileerror">troubleshooting section</a> before moving on. <span class="anchor" id="line-143"></span><span class="anchor" id="line-144"></span><p class="line874">At this point, run your map again, and you should be able to walk over the trigger and spawn a Strogg Marine into the map without a problem. <span class="anchor" id="line-145"></span><span class="anchor" id="line-146"></span><p class="line867"><img class="attachment" src="basicscripttutorial7.png" title="attachment:basicscripttutorial7.png" /> <span class="anchor" id="line-147"></span><span class="anchor" id="line-148"></span><p class="line867">
|
||
<h2 id="head-af9820085e98dbbbe969f3ffe77a211aecbfede4">What's Next?</h2>
|
||
<span class="anchor" id="line-149"></span><span class="anchor" id="line-150"></span><p class="line862">From here, you could move on to the <a href="./AdvancedScriptTutorial.html">AdvancedScriptTutorial</a>, which will show you a little more about the techniques available to you in script. You could also take a deeper look at the <a href="./ScriptVariable.html">ScriptVariable</a> page to learn more about variables and how they are used in scripting. <span class="anchor" id="line-151"></span><span class="anchor" id="line-152"></span><p class="line874">If something here didn't work out for you, check out the troubleshooting section below. <span class="anchor" id="line-153"></span><span class="anchor" id="line-154"></span><p class="line867"><a href="./ScriptFile.html">Back to the Script Shop</a> <span class="anchor" id="line-155"></span><span class="anchor" id="line-156"></span><span class="anchor" id="line-157"></span><p class="line867">
|
||
<h1 id="head-15637fe897e711af3ace5237a030b76b30b7a6a7">Tutorial Troubleshooting</h1>
|
||
<span class="anchor" id="line-158"></span><span class="anchor" id="line-159"></span><p class="line867"><span class="anchor" id="compileerror"></span> <span class="anchor" id="line-160"></span><span class="anchor" id="line-161"></span><ul><li><p class="line891"><strong>Did you forget a semicolon?</strong> <span class="anchor" id="line-162"></span><ul><li style="list-style-type:none">Remember that most command lines in script need to end with a semicolon. Check the examples to make sure your script follows exactly. <span class="anchor" id="line-163"></span><span class="anchor" id="line-164"></span></li></ul></li><li class="gap"><p class="line891"><strong>Did you forget other punctuation?</strong> <span class="anchor" id="line-165"></span><ul><li style="list-style-type:none"><p class="line862">Remember that the function needs to be enclosed entirely in <strong>{}</strong> curly braces. Did you forget one? <span class="anchor" id="line-166"></span>Did you miss a parentheses in those functions in the second example? <span class="anchor" id="line-167"></span><span class="anchor" id="line-168"></span></li></ul></li><li class="gap"><p class="line891"><strong>Did you save your script file in the right place?</strong> <span class="anchor" id="line-169"></span><ul><li style="list-style-type:none"><p class="line862">Check <a href="#savemap">here</a> to make sure you've saved your script where it belongs-- in the same folder as the map you're working on, with the same name as the map. <span class="anchor" id="line-170"></span><span class="anchor" id="line-171"></span></li></ul></li><li class="gap"><p class="line891"><strong>Did you call Reload Script from the console if necessary?</strong> <span class="anchor" id="line-172"></span><ul><li style="list-style-type:none"><p class="line862">Remember that if you changed the script file while the game is running, you need to reload them. Check out the example <a href="#reloadscript">here</a>. <span class="anchor" id="line-173"></span><span class="anchor" id="line-174"></span></li></ul></li><li class="gap"><p class="line891"><strong>First Example: Hello Stroggos</strong> <span class="anchor" id="line-175"></span></li></ul><p class="line867"><span class="anchor" id="line-176"></span><span class="anchor" id="line-177"></span><span class="anchor" id="line-178"></span><span class="anchor" id="line-179"></span><span class="anchor" id="line-180"></span><span class="anchor" id="line-181"></span><div class="codearea" dir="ltr" lang="en">
|
||
<script type="text/javascript">
|
||
document.write('<a href="#" onclick="return togglenumber(\'CA-2a540db9d772928fa1e1bef8b4cb4e8a712af8c5_002\', 1, 1);" \
|
||
class="codenumbers">Toggle line numbers<\/a>');
|
||
</script>
|
||
<pre dir="ltr" id="CA-2a540db9d772928fa1e1bef8b4cb4e8a712af8c5_002" lang="en"><span class="line"><span class="LineNumber"> 1 </span><span class="ResWord">void</span> <span class="ID">HelloStroggos</span><span class="SPChar">(</span><span class="SPChar">)</span> <span class="SPChar">{</span></span>
|
||
<span class="line"><span class="LineNumber"> 2 </span></span>
|
||
<span class="line"><span class="LineNumber"> 3 </span> <span class="ID">sys</span><span class="SPChar">.</span><span class="ID">println</span><span class="SPChar">(</span>“<span class="ID">Hello</span> <span class="ID">Stroggos</span><span class="SPChar">!</span>”<span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 4 </span></span>
|
||
<span class="line"><span class="LineNumber"> 5 </span><span class="SPChar">}</span></span>
|
||
</pre></div><span class="anchor" id="line-182"></span><span class="anchor" id="line-183"></span><ul><li><p class="line891"><strong>Second Example: Expanding to spawn a monster</strong> <span class="anchor" id="line-184"></span></li></ul><p class="line867"><span class="anchor" id="line-185"></span><span class="anchor" id="line-186"></span><span class="anchor" id="line-187"></span><span class="anchor" id="line-188"></span><span class="anchor" id="line-189"></span><span class="anchor" id="line-190"></span><span class="anchor" id="line-191"></span><span class="anchor" id="line-192"></span><span class="anchor" id="line-193"></span><span class="anchor" id="line-194"></span><div class="codearea" dir="ltr" lang="en">
|
||
<script type="text/javascript">
|
||
document.write('<a href="#" onclick="return togglenumber(\'CA-dd85c0677af322fb2d54427a8d11b97916bad6a1_003\', 1, 1);" \
|
||
class="codenumbers">Toggle line numbers<\/a>');
|
||
</script>
|
||
<pre dir="ltr" id="CA-dd85c0677af322fb2d54427a8d11b97916bad6a1_003" lang="en"><span class="line"><span class="LineNumber"> 1 </span><span class="ResWord">void</span> <span class="ID">HelloStroggos</span><span class="SPChar">(</span><span class="SPChar">)</span> <span class="SPChar">{</span></span>
|
||
<span class="line"><span class="LineNumber"> 2 </span></span>
|
||
<span class="line"><span class="LineNumber"> 3 </span> <span class="ID">sys</span><span class="SPChar">.</span><span class="ID">println</span><span class="SPChar">(</span>“<span class="ID">Hello</span> <span class="ID">Stroggos</span><span class="SPChar">!</span>”<span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 4 </span></span>
|
||
<span class="line"><span class="LineNumber"> 5 </span> <span class="ID">entity</span> <span class="ID">newMonster</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 6 </span></span>
|
||
<span class="line"><span class="LineNumber"> 7 </span> <span class="ID">newMonster</span> <span class="SPChar">=</span> <span class="ID">sys</span><span class="SPChar">.</span><span class="ID">spawn</span><span class="SPChar">(</span><span class="String">"monster_strogg_marine"</span><span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 8 </span> <span class="ID">newMonster</span><span class="SPChar">.</span><span class="ID">setWorldOrigin</span><span class="SPChar">(</span> $<span class="ID">targetMonster</span><span class="SPChar">.</span><span class="ID">getWorldOrigin</span><span class="SPChar">(</span><span class="SPChar">)</span> <span class="SPChar">)</span><span class="SPChar">;</span></span>
|
||
<span class="line"><span class="LineNumber"> 9 </span><span class="SPChar">}</span></span>
|
||
</pre></div><span class="anchor" id="line-195"></span><span class="anchor" id="line-196"></span><span class="anchor" id="line-197"></span><p class="line867"><a href="./ScriptFile.html">Back to the Script Shop</a> <span class="anchor" id="line-198"></span><span class="anchor" id="bottom"></span></div><p id="pageinfo" class="info" lang="en" dir="ltr">BasicScriptTutorial (last edited 2005-11-02 00:14:38 by <span title="JimShepard @ 67.129.250.254[67.129.250.254]"><a class="nonexistent" href="./JimShepard.html" title="JimShepard @ 67.129.250.254[67.129.250.254]">JimShepard</a></span>)</p>
|
||
|
||
<div id="pagebottom"></div>
|
||
</div>
|
||
|
||
|
||
<div id="footer">
|
||
<ul class="editbar"><li><span class="disabled">Immutable Page</span></li><li><a href="./BasicScriptTutorial?action=info">Info</a></li><li><a href="./BasicScriptTutorial?action=AttachFile">Attachments</a></li><li>
|
||
<form class="actionsmenu" method="get" action="">
|
||
<div>
|
||
<label>More Actions:</label>
|
||
<select name="action"
|
||
onchange="if ((this.selectedIndex != 0) &&
|
||
(this.options[this.selectedIndex].disabled == false)) {
|
||
this.form.submit();
|
||
}
|
||
this.selectedIndex = 0;">
|
||
<option value="raw">Raw Text</option>
|
||
<option value="print">Print View</option>
|
||
<option value="RenderAsDocbook">Render as Docbook</option>
|
||
<option value="refresh">Delete Cache</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="SpellCheck">Check Spelling</option>
|
||
<option value="LikePages">Like Pages</option>
|
||
<option value="LocalSiteMap">Local Site Map</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="RenamePage" disabled class="disabled">Rename Page</option>
|
||
<option value="DeletePage" disabled class="disabled">Delete Page</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="MyPages">My Pages</option>
|
||
<option value="SubscribeUser">Subscribe User</option>
|
||
<option value="show" disabled class="disabled">------------</option>
|
||
<option value="Despam">Remove Spam</option>
|
||
<option value="PackagePages">Package Pages</option>
|
||
</select>
|
||
<input type="submit" value="Do">
|
||
</div>
|
||
<script type="text/javascript">
|
||
<!--// Init menu
|
||
actionsMenuInit('More Actions:');
|
||
//-->
|
||
</script>
|
||
</form>
|
||
</li></ul>
|
||
|
||
<ul id="credits">
|
||
<li><a href="http://moinmoin.wikiwikiweb.de/">MoinMoin Powered</a></li><li><a href="http://www.python.org/">Python Powered</a></li><li><a href="http://validator.w3.org/check?uri=referer">Valid HTML 4.01</a></li>
|
||
</ul>
|
||
|
||
|
||
</div>
|
||
</body>
|
||
</html>
|
||
|