Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-25-2008, 10:10 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Evaluation Functions

As I said I was going to, I've created a handy set of functions for evaluating algorithms.

Features:
  • Supports operator hierarchy (took about 50% of the scripting time for me to come up with all the operator levels.
  • Accepts either in-fixed or post-fixed expressions.
  • Works with arrays.
  • Works with and without the use of ()'s

Please note that the way this script works is that it takes two kinds of expressions: in-fixed and post-fixed. The difference:
  • In-fixed: 6 + 4 * 5
  • Post-fixed: 645*+
  • In-fixed: 6 * 4 + 5
  • Post-fixed: 64*5+
In-fixed is much easier to type out for the average user and is generally easier to read. Post-fix however requires much less processing power and is much better for putting into your code.

There are basically 3 functions that you can use:
  • evl(s) - This will take an standard in-fixed gs2 expression, s and return the result. Great for making simple calculations while developing or for calculating standard in-fixed expressions. The expression, s, should be a string.
  • evalPost(s) - This function will take a post-fixed expression instead of an in-fixed one and will return the result. Post-fixed expressions can be a little more difficult to type out but don't use nearly as much processing power. This function is much better when you are going to be putting expressions into your code that won't be interpreted by a human. The expression s, must be in an array format.
  • convertToPostFix(s) - Converts an in-fixed expression (string) into a post-fixed expression (array). Good for placing your post-fixed expression into your code, that you will be placing into evalPost() once you have decided in your algorithm. This function is only needed when you are trying to turn a in-fixed expression into a post-fixed expression.

Another note:
evl(s) basically converts s into post-fixed via convertToPostFix(s) and then gives the result to evalPost(s). The result of that is what you receive. For this reason it is recommended that you use evalPost(s) when ever possible.

Things not done:
  • Didn't do operator hierarchy for most of the assignment operators.
  • Operator assignment is does not yet work. I may add this feature or I may just have a += b just give a + b.
  • Need to add more support for strings. So far @ and such works but I didn't add support for quotes and therefor, string constants.
  • I did very little bug testing so if you find any bugs, please tell me.

Hope you all like it!
- Zero

TIP:
Put the code both serverside and clientside in a class then join the class to a global object such a new TStaticVar("_"); It's what I did on my server and it works great!
Attached Files
File Type: txt eval.txt (5.3 KB, 350 views)

Last edited by zokemon; 03-26-2008 at 02:05 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.