Author Topic: Tutorial 1 - Basic Script Flow  (Read 16589 times)

0 Members and 1 Guest are viewing this topic.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Tutorial 1 - Basic Script Flow
« on: February 24, 2009, 07:28:04 AM »
0
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: [Select]
;=================================================================
; 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.

Code: [Select]
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.

Code: [Select]
gosub setup

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

Code: [Select]
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.

Code: [Select]
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:
Code: [Select]
;=================================================================
; 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 **********************************
« Last Edit: August 03, 2010, 12:47:58 PM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline UOMaddog

  • Maddog
  • Elite
  • *
  • *
  • Posts: 1625
  • Activity:
    0%
  • Reputation Power: 22
  • UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...
  • Gender: Male
  • Biggest B@D@$$ of the Universe
  • Respect: +165
  • Referrals: 8
    • View Profile
    • Insane UO
Re: 1 - Basic Script Flow
« Reply #1 on: April 19, 2009, 09:19:30 AM »
0
You can also use:
Code: [Select]
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:
Code: [Select]
repeat
  blah
  blah blah
  blah blah blooey
  while #charghost = yes
     wait 0
until #charghost = yes
There are 10 kinds of people in this world: those that understand binary and those that don't!

Windows:  A 64-bit tweak of a 32-bit extension to a 16-bit user interface for an 8-bit operating system based on a 4-bit architecture from a 2-bit company that can't stand 1 bit of competition!

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Tutorial 1 - Basic Script Flow
« Reply #2 on: September 20, 2011, 06:33:25 AM »
0
stickied
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Tags: