View unanswered posts | View active topics It is currently Thu Aug 22, 2019 1:38 pm



Reply to topic  [ 1 post ] 
 How-to Passing Parameters to a goSub 
Author Message
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post How-to Passing Parameters to a goSub
One of the issues I deal with is the inability to pass parameters for certain scripts to a goSub. An example of a workaround is below, but it is just typed in and not tested. It is a simple right side padding gosub, and does have a limitation in that you must know how many words are in it - this version anyway ;) I will leave it up to you to figure out what my actual version is where it doesn't require any previous word count knowledge since it is easy to do.

There are scripts out that do this already, most bots for instance, but for a new scripter writing their first scripts w/o coding knowledge this might help. Feel free to post improvements to this and alternate ways of doing it such as making it a pad routine for left and right and center.

Code:
      // I want the gosub, padR to be reusable so
      // I pass it the variable to be padded and a second entry as the length.
      // So to pad a sector number to a length of 5, the following would work

      //                       |- var to pad
      //                       |           |- length to pad
      //                       v          v
        setVar $padR $firstHit[$sect] & " 5"
        goSub :padR
        setVar $gType[$lineCnt] $padR & " -- Some information"
       
        // goSubs

       :padR
            // get the length of padding from our variable                           
         getword $padR $padding 2
           // get the actual word in the variable to pad
         getword $padR $padR 1
           // get the vars length
         getLength $padR $len
           // do it
         setVar $i 1
         while ($i <= $padding)
             setVar $padR $padR & " "
             add $i 1
          end
          return


_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sun Oct 23, 2011 2:16 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.