Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-28-2011, 03:19 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
evalArray()

I've written a small function that basically applies a calculation to all elements of an array using Zero's eval function.

Here it is:
PHP Code:
function evalArray(arrev) {
  if (
arr[0].size() == 0)
    
arr = { arr };
  
  
// evaluate all array elements
  
temp.nArr = new[arr[0].size()];
  for (
temp.0arr[0].size(); i++) {
    
temp.eva ev;
    for (
temp.0eva.size(); k++)
      for (
temp.0arr.size(); l++)
        if (
eva[k] == "E" l)
          
eva[k] = arr[l][i];
    
    
nArr[i] = evalPost(eva);
  }
  
  return 
nArr;

The first argument is either a single array of values to use in the calculations or an array of multiple arrays holding values (if you want to use more than one). The function will return an array the size of the (first) value array, holding all the solutions.

The second argument is your formula in post-fix notation (more on that in Zero's thread). In this array you can use E0, E1, E2 and so on to refer to the current array element of the specific array (starting at 0, obviously) depending on how many arrays you've given to the function.


Example:
PHP Code:
temp.a1 = { 12};
temp.a2 = { 45};
echo(
evalArray({ a1a2 }, { "E0""E1""+"2"*" })); // returns { 10, 14, 18 } 

Maybe this is useful for some of you guys. I've written it for a project of mine.
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:48 AM.


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