Shared Functions()

Discussions and file drops for Auggie
Amazon [Bot]
Full Member
Full Member
Posts: 185
Joined: Tue Jan 06, 2026 4:56 pm

Re: Shared Functions()

Post by Amazon [Bot] »

GlennD wrote: P.S. Did look up the Game Monkey and it does mention that no switch is available so blocks of if statements it is.  :D
I found this example and it worked for me.

Code: Select all

name = "pear";
switch (name)
{
  case "apple": { print("hurrah "); print("for apples"); } // braces are required
  case "banana":                                       // Fall through multiple cases
  case "pear":
  case "cherry": { print("fell to fruit", name); } 
  case favoriteFruit: { print("my favorite fruit"); }     // allow variable cases!
  default: { print("no fruit for you"); }                 // Default not required
}

 fell to fruit pear  
DanL
Site Admin
Posts: 357
Joined: Thu Sep 11, 2014 12:35 am

Re: Shared Functions()

Post by DanL »

Amazon [Bot]
Full Member
Full Member
Posts: 185
Joined: Tue Jan 06, 2026 4:56 pm

Re: Shared Functions()

Post by Amazon [Bot] »

How about a simple sorting routine?

Code: Select all

global  BubbleSort = function(iarray,num)  
{	
d={""};
   print("Unsorted Data:");
   for (k = 0; k < num; k=k+1) 
   {
      print(iarray[k]);
   }
   for (i = 1; i < num; i=i+1) 
   {
      for (j = 0; j < num - 1; j=j+1) 
      {
         if (iarray[j] > iarray[j + 1]) 
         {
            temp = iarray[j];
            iarray[j] = iarray[j + 1];
            iarray[j + 1] = temp;
         }
      }
   }
   print("Sorted & After pass: " + k);
   for (k = 0; k < num; k=k+1) 
   {
     print(iarray[k]);
     d[k] = iarray[k]; 
   }
return;
};
a={33,6,11,3,"k","e","y"}; // the data array
b=tableCount(a); // number of items in the array
BubbleSort(a,b);


Unsorted Data:  
 33  
 6  
 11  
 3  
 k  
 e  
 y  
 Sorted & After pass: 7  
 3  
 6  
 11  
 33  
 e  
 k  
 y  


Amazon [Bot]
Full Member
Full Member
Posts: 185
Joined: Tue Jan 06, 2026 4:56 pm

Re: Shared Functions()

Post by Amazon [Bot] »

Converting a Hex to a number
HexString is a Hex number represented as a string
Hex letters can be Upper or Lower case

Code: Select all

global  HexStringToNum = function(HexString) 
{ 
    HexString = ToString(HexString);
    local char = "";
    local rHexString = "";
    local Val = 0;
    local indx = 0;
    local StringAsNum = 0;
    local ZeroForNilChar = 0;
    local StringLength = HexString.Length(HexString);    
    rHexString = HexString.Reverse(HexString);    
//debug();
  for (x = 0; x < StringLength; x=x+1)
    {
        indx = x + 1;        
        char = rHexString.Mid(indx-1,1);
        if (char == null)
          {
            char = "0"; Val = 0;
           }
        if (char == "A" or char == "a")
          {
            Val = (10 * math.power(16, indx-1));
          }
        else if (char == "B" or char == "b")
          {
            Val = (11 * math.power(16, indx-1));
          }
        else if (char == "C" or char == "c" )
          {
            Val = (12 * math.power(16, indx-1));
          }
        else if (char == "D" or char == "d")
          {
            Val = (13 * math.power(16, indx-1));
          }
        else if (char == "E" or char == "e")
          {
            Val = (14 * math.power(16, indx-1));
          }
        else if (char == "F" or char == "f")
          {
            Val = (15 * math.power(16, indx-1));
          }
        else //  if (char.String != "string")
          {
            Valt = ToInt(char);
            if (Valt == null) 
            {
                ZeroForNilChar = 0;
                Val = 0;
            }
            else
            {
                Vals = ToInt(char);
                Val = (Vals * math.power(16, indx-1));
            }
           }         
        StringAsNum = StringAsNum + Val; 
        local dummy = 0;
        } 
    local dummyvar = StringAsNum;
    return StringAsNum;
};
stringasnum = HexStringToNum("22AF2DE");
print(stringasnum);

36369118

Amazon [Bot]
Full Member
Full Member
Posts: 185
Joined: Tue Jan 06, 2026 4:56 pm

Re: Shared Functions()

Post by Amazon [Bot] »

temperature conversions

Code: Select all

global  Temp_F_to_C = function(F) 
{
  F=ToFloat(F);
  celsius=(5.0/9.0)*(F -32.0);
  return celsius;
};
global  Temp_C_to_F = function(C) 
{
  C=ToFloat(C);
  Fehr=((9.0/5.0)*C) +32.0;
  return Fehr;
};
User avatar
Mooselake
Site Admin
Posts: 512
Joined: Sun Dec 26, 2010 11:21 pm
Location: Mooselake Manor

Re: Shared Functions()

Post by Mooselake »

The linked GM (have to wonder if GameMonkey was an obvious choice for Gearotic Motion :) ) script reference only mentions switch() in an example, although they say it uses flex as a parser.  Too many family things going on today to dig deeper today (like how much of flex gets carried along, does based on mean incorporating?).  The Lua reference doesn't mention switch either.  Something strange is going on here...  I'll mention I'm not very enthused about the "read the source code and figure it out" style of documentation, but maybe that's necessary to see just what's included in the language.

Wonder if you could use array constructors to do pre-sorted tables?  From the quick doc scan that's kinda ambiguous, too.

Kirk


ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: Shared Functions()

Post by ArtF »

Kirk:

  Its a fantastic scripter, but there are tons of ambiguities.. :)

Art
User avatar
Mooselake
Site Admin
Posts: 512
Joined: Sun Dec 26, 2010 11:21 pm
Location: Mooselake Manor

Re: Shared Functions()

Post by Mooselake »

ArtF wrote:Its a fantastic scripter, but there are tons of ambiguities.. :)
That's what makes it so much fun :)

I found a lengthy discussion of Tempest on the Mach3 forum that's taking a big chunk of that elusive spare time, plus the head scratching is risking the few remaining follicles.  I didn't realize that you'd discovered 3rd order S curve motion long before the tinyg guys, but I'm not surprised.

Kirk
Last edited by Mooselake on Fri Dec 25, 2015 8:53 pm, edited 1 time in total.
GlennD
Site Admin
Posts: 80
Joined: Wed Oct 19, 2011 3:19 am

Re: Shared Functions()

Post by GlennD »

Group, sorry about the switch thing, I thought I had tried the braces in the case portion guess not.
I had tried several variants before I went looking at the Game Monkey stuff.

Hope everyone is having a wonderful Christmas.

Glenn

Edit:
Even funnier is when you look further down on the page as linked above and where I found that it said didn't use switch. you see switch used in the Constructor with Parameters example.  The example isn't using the braces.

You do not have the required permissions to view the files attached to this post.
Last edited by Anonymous on Sat Dec 26, 2015 2:30 am, edited 1 time in total.
ArtF
Global Moderator
Global Moderator
Posts: 4557
Joined: Sun Sep 05, 2010 5:14 pm
Contact:

Re: Shared Functions()

Post by ArtF »

Glenn:

:), yes, your seeing my only issue with Game Monkey script, its a bit hard to figure the rules, and Ive modified it
quite a bit as well, the scripts are preemptive now in some cases for example, necessary for Auggie because someone,
somewhere at some time will do a

while(1) { };

and lock up a system with a thread that never ends. The system tries to detect that and will put to sleep
a thread that takes more than 50ms or so. If, ( and it can happen) this fails to happen and a system appears locked
from a thread you wrote, Auggie has a "Three-Finger Salute" that kills all running threads. Ctrl-Shift-Alt. This kills
any threads running.

  Monkey Script is a very easy and fun language, unlike VB in Mach3, where I dreaded even thinking of writing a
routine, Im finding I actually like scripting in Monkey for the most part. Ive modified it here and there to suit
Auggies needs, the Docs will need work as I release data for you guys to see how things interact, but as a
script engine decision, Im pretty happy with GM script.

(It does sound as if it were made for Gearotic Motion doesnt it?)

 Im glad youve enjoyed playing in it, between you and YNN its firming up how I will go forward
with the next scripting system dedicated to the GCode callable scripts. Its a challenge to make that easy,
not too complex and powerfull enough to make a differerence.
     I've decided I'll be doing it to a similar fashion as World of Warcraft Plugins actually, so the
worlds gaming systems are definitely having a major impact on Auggies development, and before
anyone thinks thats a disparaging thing to say, consider for a moment that just Game Monkey Script alone probably
has more development investment in it than Mach3 did after 4 years of development.
World of Warcraft has had hundreds of millions of dollars spent in their development over 10
years, and I follow such things as proof of direction for evolving software when I write things.

  Now Im not as good as they are, so you guys need to keep commenting on what you
find easy, and what you find nasty, where I can adapt I will.  

Thx
Happy New Year
Art


Last edited by ArtF on Sat Dec 26, 2015 2:10 pm, edited 1 time in total.
Post Reply