Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Arithmetic expression evaluation in numeric input fields.

SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
10-20-2006 23:38
The sign designing program I use at work lets us enter arithmetic expressions in the numeric entry fields. For example, if the letter height field shows 2.345, and I want it to be doubled, I don't have to calculate the value elsewhere and enter it manually, I just add "*2" following the 2.345 and tab or press enter and the value changes to 2.345*2.
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
10-21-2006 10:15
I'd like to see this, and I'd want the fields to be a little wider. My friend suggested this awhile back: /13/13/38801/1.html
Angel Fluffy
Very Helpful
Join date: 3 Mar 2006
Posts: 810
10-21-2006 10:52
Interesting idea. It'd be nice for novice builders... though from what I have seen, many of the more experienced builders have tools that change prim properties via a HUD, thus meaning the builder can change prims with HUD clicks and doesn't have to mess with numbers in boxes.
_____________________
Volunteer Portal (FAQs!) : https://wiki.secondlife.com/wiki/Volunteer_Portal

JIRA / Issue Tracker : http://jira.secondlife.com (& http://tinyurl.com/2jropp)
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
11-13-2008 21:46
I created a Jira issue on this topic back in May of 2007, https://jira.secondlife.com/browse/VWR-675, "Ability to do simple math in numeric edit fields"

A comment by Aimee Trescothick appeared there November 12th reporting
From: someone
Have had this working nicely for a while now, just need to find time to clean it up and make the patch, RL keeps getting in the way :S


Congratulations and thanks to Aimee Trescothick.

Perhaps it's time to vote for this Jira issue .
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
12-17-2008 12:36
Good news from Aimee Trescothick
From: Aimee Trescothick in the jira comments
OK, I'm attaching a patch of it in its current state I know some people are eager to play with it

http://jira.secondlife.com/browse/VWR-675
From: someone
Ability to do simple math in numeric edit fields

It would be useful to be able to do simple math in numeric edit fields.

Example:
An object is at postion X = 10.254.

You want to move it by 2.358 meters in the x direction.

Type "+2.358" after "10.254" in the object's X positon field and press enter.

The sum of the two numbers appears in the edit field and the object moves to that postion.

We can do this in the design program I use at work and I use it a lot.


Outstanding!

More votes would be nice.
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
12-17-2008 13:15
Off the top of my head:

CODE

list DIGITS = [
"0", "1", "2", "3", "4",
"5", "6", "7", "8", "9"
];

list digits(string s)
{
string token = llGetSubString(s, 0, 1);
s = llGetSubString(s, 1, -1);
while(token == " ")
{
token = llGetSubString(s, 0, 1);
s = llGetSubString(s, 1, -1);
}

string result = "";
while(llListFindList(DIGITS, [token]) != -1)
{
result += token;
token = llGetSubString(s, 0, 1);
s = llGetSubString(s, 1, -1);
}

while(token == " ")
{
token = llGetSubString(s, 0, 1);
s = llGetSubString(s, 1, -1);
}

return [result, token, string];
}

list term(string s)
{
list l = digits(s);
string value = llList2String(l, 0);
string token = llList2String(l, 1);
string = llList2String(l, 2);

if(token == ".") {
l = digits(s);
value = value + "." + llList2String(l, 0);
token = llList2String(l, 1);
string = llList2String(l, 2);
}

return [ (float)value, token, string ];
}


list prod(string s)
{
list l = term(s);
float value = llList2Float(l, 0);
string token = llList2String(l, 1);
string = llList2String(l, 2);
while(token == "*" || token == "/") {
l = term(s);
if(token == "*") value *= llList2Float(l,0);
else value /= llList2Float(l, 0);
token = llList2String(l, 1);
string = llList2String(l,2);
}
return [value, token, string];
}

list sum(string s)
{
list l = prod(s);
float value = llList2Float(l, 0);
string token = llList2String(l, 1);
string = llList2String(l, 2);
while(token == "+" || token == "-") {
l = prod(s);
if(token == "+") value += llList2Float(l,0);
else value -= llList2Float(l, 0);
token = llList2String(l, 1);
string = llList2String(l,2);
}
return [value, token, string];
}

float eval (string expr)
{
list l = sum(expr);
return llList2Float(l, 0);
}

No warranty intended or implied, it probably doesn't even compile, but I've desk-checked it and if it doesn't compile a scripter of average ability should be able to get it to work.
_____________________
Argent Stonecutter - http://globalcausalityviolation.blogspot.com/

"And now I'm going to show you something really cool."

Skyhook Station - http://xrl.us/skyhook23
Coonspiracy Store - http://xrl.us/coonstore
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
12-24-2008 18:13
There's a viewer patch already written.

If that's an LSL script it's not real applicable to the topic.
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
02-22-2009 20:52
Expression evaluation for builders has been implemented in the Imprudence viewer.

Here's the url on the topic at the Imprudence wiki: http://imprudenceviewer.org/wiki/Build_Math_Expressions .

It's a fair bit more advanced that what I was hoping for. It has variables and constants added in. I just moved something by typing "+5" at the end of the current postion and it added 5 to the current position and moved the object there.

Far out!

This was implemented by Aimee Trescothick . Thanks for the work, Aimee.

I hope this or something similar makes it into the regular SL viewer; I know builders will love it once they see it.

The Imprudence web site is at http://imprudenceviewer.org/ . There are Windows and Linux versions with the expression evalualtor and also with a number of interesting changes in the interface. Might as well give it a try.
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-