Hi Marlou,
I'm not certain if you had the opportunity to look at the present DarkLUA code but here is a small excerpt of code from S3GE
START:
//! Initialize
dbSyncOn();
dbSyncRate(60);
S3GE::scriptstart();
LPSTR testscript =
{
"speedx = 2\n"
"speedy = 2\n"
"speedz = 3\n"
"dbObjectSpin(1,speedx,speedy,speedz)\n"
"return 0\n"
};
int scripttaskID = S3GE::scripttaskcreate(0, "testscript1", testscript);
S3GE::scripttaskrun(scripttaskID);
UPDATE:
//! Primary Update Loop
while (LoopGDK()){
//scripting engine .testing
S3GE::scriptupdate();
if(S3GE::scripterrorflagget()){ dbText(0, dbScreenHeight() - 16, S3GE::scripterrormessageget());}
//! Primary Sync
dbSync();
}
STOP:
//! Terminate
S3GE::scriptstop();
return;
}
How it works is a script is loaded into a task via the
S3GE::scripttaskcreate(). Each task is a self-contained block of script that independently executed. The
S3GE::scriptupdate() is called in the primary game loop. It iterates thru each executing the batch. Tasks have methods to exec (on the fly), suspend/pause, and kill the task. I will be including methods to add/remove the task from the update iteration, and modify position (priority) in the update.
This design was inspired by how I implemented Scripting in
MAUI for DBPro. MAUI was designed to operate like a Web Browser requesting *maui pages with XML Markup for formatting Gizmos & LUA for client side scripting. MAUI Gizmos are treated like little event-driven Bots and packaged scripts for specific tasks: Behaviors, Transitions, Styles, and Themes based on event state.
Here an example of *.maui file.
<maui version = "2.0">
<meta name="loading" content="unload" />
<meta name="script" content="credits" language="darklua">
MMO_Credit = 0
MMO_Credits = {}
MMO_Credits[1] = 'CREDITS'
MMO_Credits[2] = 'Engine: Server/Client Programmer - F.L.Taylor'
MMO_Credits[3] = 'Plugin: DarkPhysics/DarkAI - TheGameCreators.com'
MMO_Credits[4] = 'Plugin: Matrix1Util - Ian Mold'
MMO_Credits[5] = 'Plugin: LUA Scripting - Barnski'
MMO_Credits[6] = 'Plugin: DBXML - Thomas Cheah'
MMO_Credits[7] = 'Plugin: Octree Culling - Diggsey'
MMO_Credits[8] = 'Game: `META-Lore` Concept/Design - F.L.Taylor'
MMO_Credits[9] = 'Music: `META-Lore` Intro - F.L.Taylor'
MMO_CreditsTotal = 9
</meta>
<img src="2D/Splash3.jpg" width="1024" height="768" theme="0" usemap="mmo_ClientStart" />
<map name="mmo_ClientStart" style="backdrop" behavior="label" bgsound="Audio/Music/mmo_clientstart.mp3" visible="1">
<area name="client" shape="rect" coords="4,3,355,22" style="default" behavior="label" alt="Title" theme="0" visible="1" halign="left" valign="top" caption="META-Lore Client by F.L.Taylor"/>
<area name="clientdate" shape="rect" coords="4,22,372,40" style="default" behavior="label" alt="StartDate" theme="0" visible="1" halign="left" valign="top" caption="Start Date: Mon Jun 15 18:41:24 MST 2009"/>
<area name="usernameframe" shape="rect" coords="380,369,693,431" style="default" behavior="label" theme="default" visible="1"/>
<area name="usernamelabel" shape="rect" coords="390,379,466,398" style="bolder" behavior="label" alt="Username" visible="1" halign="left" valign="middle" caption="UserName"/>
<area name="passwordlabel" shape="rect" coords="390,402,466,420" style="bolder" behavior="label" alt="Password" visible="1" halign="left" valign="middle" caption="Password"/>
<area name="username" shape="rect" coords="466,379,632,398" style="inputbox" behavior="input" transition="ghostly" alt="Username" theme="inputter" visible="1" collision="1" halign="left" valign="middle" caption="Guest"/>
<area name="password" shape="rect" coords="466,402,632,420" type="password" style="inputbox" transition="ghostly" behavior="input" alt="Password" theme="inputter" visible="1" collision="1" halign="left" valign="middle" caption="Guest"/>
<area name="start" shape="rect" coords="635,379,683,421" style="gamey" behavior="button" transition="ghostly" alt="Start" theme="theory" visible="1" collision="1" caption="Start">
<event type="UP" count="0" caption="Starting">
<script language="darklua">
DBPro.Call('MAUI_HTTPFormSubmit','www.hpquest.com',80,2,'/MOR/Data/UI/mmo_clientlaunch.php')
</script>
</event>
</area>
<area name="fps" shape="rect" coords="808,4,931,57" style="meter" behavior="label" alt="FPS" caption="FPS"/>
<area name="reload" shape="rect" coords="1000,0,1024,18" alt="Reload" style="default" behavior="button" transition="ghostly" align="center" theme="3" visible="1" collision="1">
<event type="IDLE" count="0" caption="R"></event>
<event type="UP" count="0" caption="L">
<script language="darklua">
DBPro.Call('MAUI_HTTPFormSubmit','www.hpquest.com',80,2,'/MOR/Data/UI/mmo_clientlogin.php');
</script>
</event>
</area>
<area name="credits" shape="rect" coords="369,458,681,476" style="gamey" behavior="label" halign="center" alt="Credits" theme="0" visible="1">
<event type="IDLE" count="0">
<script language="darklua" type="1">
MAUI_GizmoEventID = DBPro.Call('MAUI_GizmoEventIDTableGet',MAUI_GizmoID,0)
MAUI_GizmoImageID = DBPro.Call('AsInt',DBPro.Call('MAUI_GizmoEventPropertyGet',MAUI_GizmoEventID,'ImageID'))
MAUI_GizmoImageAlpha = DBPro.Call('SpriteAlpha',MAUI_GizmoImageID)
DBPro.Call('MAUI_GizmoPropertySet',MAUI_GizmoID,'EventTypeCounter',DBPro.Call('AsString',DBPro.Call('MAUI_GizmoPropertyGet',MAUI_GizmoID,'EventTypeCounter') + 1))
MAUI_GizmoEventTypeCounter = DBPro.Call('AsInt',DBPro.Call('MAUI_GizmoPropertyGet',MAUI_GizmoID,'EventTypeCounter'))
if MAUI_GizmoEventTypeCounter == 555 then
DBPro.Call('MAUI_GizmoPropertySet',MAUI_GizmoID,'EventTypeCounter','0')
elseif MAUI_GizmoEventTypeCounter > 427 then
MAUI_GizmoImageAlpha = MAUI_GizmoImageAlpha - 2
if MAUI_GizmoImageAlpha < 0 then MAUI_GizmoImageAlpha = 0 end
DBPro.Call('SetSpriteAlpha',MAUI_GizmoImageID,MAUI_GizmoImageAlpha)
elseif MAUI_GizmoEventTypeCounter > 250 then
MAUI_GizmoImageAlpha = MAUI_GizmoImageAlpha + 2
if MAUI_GizmoImageAlpha > 255 then MAUI_GizmoImageAlpha = 255 end
DBPro.Call('SetSpriteAlpha',MAUI_GizmoImageID,MAUI_GizmoImageAlpha)
elseif MAUI_GizmoEventTypeCounter == 250 then
if MMO_Credit == MMO_CreditsTotal then MMO_Credit = 0 end
MMO_Credit = MMO_Credit + 1
DBPro.Call('MAUI_GizmoEventPropertySet',MAUI_GizmoEventID,'Caption',MMO_Credits[MMO_Credit])
DBPro.Call('MAUI_GizmoEventImageCapture',MAUI_GizmoID,0)
end
</script>
</event>
</area>
<area name="exit" shape="rect" coords="934,745,1015,763" style="default" behavior="button" transition="ghostly" alt="Exit MMO Client" theme="3" visible="1" collision="1">
<event type="IDLE" src="2D/mmo_clientexit_hover.jpg" caption="Exit"/>
<event type="DOWN" src="2D/mmo_clientexit_hold.jpg" caption="Exit"/>
<event type="HOLD" src="2D/mmo_clientexit_hold.jpg" caption="Exit"/>
<event type="HOVER" count="0" caption="Leaving?"/>
<event type="UP" count="0" caption="Bye Bye!">
<script language="darklua">
DBPro.Call('DebugPrint','exit MAUI_GizmoID = '..MAUI_GizmoID)
DBPro.Call('MMO_ClientTerminate')
</script>
</event>
</area>
</map>
</maui>
The key phrase here is
packaged scripts for specific tasks. To strive for greatest performance, I'm going to try to avoid creating a
soft engine.
If your still interested in making your own script parser or script engine for NPC scripts I may be of some assistance. I developing DittoTPU I'm writing a script engine. Its sorta funny because I'm writing it input function prototypes and output a DarkLUA binding function.
DittoTPU Example
Input
Ditto TPU is gonna rock!<@
a = 1
b = 1 + 1
@>Hello << >> World<@
c = a*b + a/b
if a < b then call a else call b
@>as the world turns<@
if c < b then call a else call a
@>Goodbye
Output
DittoTPU Compile
out "Ditto TPU is gonna rock!"
mov eax,1
mov [_a],eax
mov eax,1
push eax
mov eax,1
pop ecx
add eax,ecx
mov [_b],eax
out "Hello "
out "<<"
out " "
out ">>"
out " World"
mov eax,[_a]
push eax
mov eax,[_b]
pop ecx
imul eax,ecx
push eax
mov eax,[_a]
push eax
mov eax,[_b]
mov ecx,eax
pop ecx
idiv eax,ecx
pop ecx
add eax,ecx
mov [_c],eax
mov eax,[_a]
push eax
mov eax,[_b]
pop ecx
cmp ecx,eax
slt eax
and eax,255
and eax,eax
jz __1
mov eax,[_a]
call &
jmp __2
__1:
mov eax,[_b]
call &
__2:
out "as the world turns"
mov eax,[_c]
push eax
mov eax,[_b]
pop ecx
cmp ecx,eax
slt eax
and eax,255
and eax,eax
jz __3
mov eax,[_a]
call &
jmp __4
__3:
mov eax,[_a]
call &
__4:
out "Goodbye
"
ret
_a:
dd 0
_b:
dd 0
_c:
dd 0
Done!
The psuedo ASM instructions will be used to create stack machine to process script. DittoTPU uses a special Markup. A simple Markup similar to HTML may be useful for formatting the text within the Dialog. I will not even mentioned client side scripting, hehe.