PDA

View Full Version : Calculating



Fenloh
October 12th, 2008, 10:27
That is the code:


<script>
function onUpdate()
local bodycheckvalue= window.bodycheck.getValue();
local pdamvalue = 0 ;
pdamvalue = (bodycheckvalue/2) + 8;

window.stat.pdam.score.setValue(pdamvalue);
end
</script>



I want to calculate half of the body attribute and add 8 to a local Variable and then out the value to the correct field.

the bodycheck does not have a source, i access it directly
the pdam has the source stat.pdam.score

1. Is the code correct so far?
2. how can i round a Variable (round roundup rounddown) within the script
3. is there some way to echo a variable to the console, so i can actually see if it is filled or not? or is there a debugger?

Thanks again for even looking into the code.

Fenloh

Foen
October 12th, 2008, 22:25
Okies, here are a few answers.

You might want to try DB.findNode("stat.pdam.score") if your pdam value is held at a hard-wired location in the db.

Rounding can be achieved using math.floor(x/2) which always rounds down. Other math library functions can be found in the Lua reference here (https://www.lua.org/manual/5.1/).

To send something to the console, use print(somestringvalue); You will also need to issue the /console command before you can see the output.

Hope that helps

Stuart

Fenloh
October 12th, 2008, 22:50
Thanks, found it and works fine!

Fenloh