# lsl question about a percentage decrease and increase system.

## Recommended Posts

Hello, I'm not much good at scripting but I've been making a very simple interactive pet, it has sounds on touch and you can pet it and change it's name but i was wondering since i can't find it anywhere i have looked would a percentage system such as a hunger bar that decreases over time and a menu button that increases the percentage be a lot of work, i have looked everywhere for a percentage based script and pet script but I've only come across breedables which are to much for what i want, don't want people to pay for food only role play, thanks a lot I'm a big noob

##### Share on other sites

You can calculate hunger like this:

integer nProcent = (integer)((nHunger/100)*100);

Increase value simply by after say a touch or defined time interval:

nHunger++;

if (nHunger>100)

nHunger= 0;

Display value or build a string by adding for example " โ" using llSetText() with a for loop

for (i=0; i<=nProcent, i++)

str+="โ";

Now we would get a string with 100 chars, which is a little overkill - limit it to say 10 chars, so each char represent 10%. Divide nProcent with 10 and be sure to cast the value an integer before using it in for loop.

##### Share on other sites

when our hunger bar is a maximum of 10 bars wide (10% per bar)

and 'hunger' is some integer value in [0..9] and 10 bars is really hungry:

string bar = llGetSubString("โโโโโโโโโโ", 0, hunger);

going the other way, where 10 bars is not hungry and 1 bar is really hungry:

string bar = llGetSubString("โโโโโโโโโโ", 0, 9 - hunger);

##### Share on other sites

You can also use a primย to indicate percentage... a bar-scale with a cube, or a pie-chart with a cylinder:

```// Bar Scale - Slice a BOX from 1.0 to 0.02

float hunger = 1.0; // 1.0 is 100% of 1
timer() {
hunger -= 0.01;
llSetPrimitiveParamsFast([PRIM_SLICE, <0.0, hunger, 0.0>]);
}

// Pie Chart - Cut a CYLINDER from 1.0 to 0.02

float hunger = 1.0; // 1.0 is 100% of 1
timer() {
hunger -= 0.01;
llSetPrimitiveParamsFast([PRIM_TYPE, PRIM_TYPE_CYLINDER, PRIM_HOLE_DEFAULT, <0.0, hunger, 0.0>, 0.0, ZERO_VECTOR, ZERO_VECTOR, ZERO_VECTOR]);
}```

ย

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.