Official ScriptUO EasyUO Scripts > Scripting Tutorials

Tutorial 1 - Basic Script Flow

(1/1)

Cerveza:
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


--- Code: ---;=================================================================
; 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}
;=================================================================

--- End code ---

Setup: set variables, get user inputs, display menu.


--- Code: ---set %var1 500
set %books 3

--- End code ---

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.


--- Code: ---gosub setup

--- End code ---

Mainloop: this is the portion of the script that loops the repetitive actions.


--- Code: ---SUO:
repeat

if something
  gosub do_it
if something else
  gosub do_this_instead

until #CharGhost = YES
while #CharGhost = YES
  wait 1
GoTo SUO

--- End code ---

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.


--- Code: ---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

--- End code ---

Menu: if used. Usually put at the end of the script.

So there it is, your script would look like this:

--- Code: ---;=================================================================
; 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 **********************************

--- End code ---

UOMaddog:
You can also use:

--- Code: ---repeat
   repeat
     blah
     blah
     blah
   until #charghost = yes
   while #charghost = yes
     wait 0
until #charghost = yes
--- End code ---


Which after reading I just realized can be simplified to:

--- Code: ---repeat
  blah
  blah blah
  blah blah blooey
  while #charghost = yes
     wait 0
until #charghost = yes
--- End code ---

Cerveza:
stickied

Navigation

[0] Message Index

Go to full version