ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Tutorials => Topic started by: Cerveza on February 24, 2009, 07:28:04 AM
-
Basic Script Flow
Just to give everyone a fundamental understanding of how a script should flow.
Header
Setup
Mainloop
Subs
Menu
Header: The script title, date, version, thanks, setup, explaination
;=================================================================
; Script Name: Cerveza's Example of a Header
; Author: Cerveza
; Version: 1.3b
; Shard OSI / FS: OSI / FS OK
; Revision Date: 2/24/2009
; Purpose: Show people what a header looks like
; Globals: None
;=================================================================
; Special Instructions: You can put in some of the setup
; and running instructions here. Any disclaimers you want or
; any other information you want the user to know about your
; script. A more detailed Purpose could go here as well. If
; your script is a sub routine, you MUST include how to call
; the sub in this section:
;
; %1 - NPC ID
; %2 - Item ID
; %3 - Number of Items
;
; set %npc_id XXYYZZ1
; gosub TM_BuyAgent_ID %npc_id OIK 5 ; 5 wooden shields
;
; Thanks: {Name and reason}
;=================================================================
Setup: set variables, get user inputs, display menu.
set %var1 500
set %books 3
If you have more then a couple things to be setup, or extended setups including user interactions (click on your runebook to continue) then use a sub routine.
gosub setup
Mainloop: this is the portion of the script that loops the repetitive actions.
SUO:
repeat
if something
gosub do_it
if something else
gosub do_this_instead
until #CharGhost = YES
while #CharGhost = YES
wait 1
GoTo SUO
I like this one because it doesn't use a dreaded "GOTO" unless your dead. Actually when you come back to life it uses the one GOTO statement. The "wrapper" can be used with any script.
SUO:
repeat
...
until #CharGhost = YES
while #CharGhost = YES
wait 1
GoTo SUO
It will continue to loop between the "repeat/until" and when you are a ghost it will go to the next line and wait until your no longer a ghost then start looping again.
Sub Routines: where the script actions really take place.
sub do_it
; this is where you would perform the actions identified in the mainloop.
return
sub do_this_instead
; this is where you would perform these other actions identified in the mainloop.
return
Menu: if used. Usually put at the end of the script.
So there it is, your script would look like this:
;=================================================================
; Script Name: Cerveza's Example of a Header
; Author: Cerveza
; Version: 1.3b
; Shard OSI / FS: OSI / FS OK
; Revision Date: 2/24/2009
; Purpose: Show people what a header looks like
; Globals: None
;=================================================================
; Special Instructions: You can put in some of the setup
; and running instructions here. Any disclaimers you want or
; any other information you want the user to know about your
; script. A more detailed Purpose could go here as well. If
; your script is a sub routine, you MUST include how to call
; the sub in this section:
;
; %1 - NPC ID
; %2 - Item ID
; %3 - Number of Items
;
; set %npc_id XXYYZZ1
; gosub TM_BuyAgent_ID %npc_id OIK 5 ; 5 wooden shields
;
; Thanks: {Name and reason}
;=================================================================
;************************ Setup **********************************
set %var1 500
set %books 3
;*********************** Main Loop *******************************
SUO:
repeat
if something
gosub do_it
if something else
gosub do_this_instead
until #CharGhost = YES
while #CharGhost = YES
wait 1
GoTo SUO
;************************* Subs **********************************
sub do_it
; this is where you would perform the actions identified in the mainloop.
return
sub do_this_instead
; this is where you would perform these other actions identified in the mainloop.
return
;************************* Menu **********************************
-
You can also use:
repeat
repeat
blah
blah
blah
until #charghost = yes
while #charghost = yes
wait 0
until #charghost = yes
Which after reading I just realized can be simplified to:
repeat
blah
blah blah
blah blah blooey
while #charghost = yes
wait 0
until #charghost = yes
-
stickied