Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

math question

Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
02-04-2008 22:51
For a new camping device i'm working on, I have a bit of a math problem... The timer runs every 60 seconds (1 minute) and it adds time to variable "minutes". once it equals "cycletime" I want it to add some money to how much you've earned sofar. BUT variable "minutes" keeps going from there so I need a way to find out if minutes is divisible by cycletime. so assuming cycletime is 3 it pays every time minutes is 3, 6, 9, 12...ect



right now I tried using how much ive earned to calculate it but it messes up sometimes.
if (minutes/cycletime == made/makepercycle)
Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
02-04-2008 23:15
Nevermind, I finally got it. Here's the answer for anybody that also wants to know...


if x - (x / y) * y = 0
Beezle Warburton
=o.O=
Join date: 10 Nov 2006
Posts: 1,169
02-04-2008 23:16
From: Yamil Dagger
For a new camping device i'm working on, I have a bit of a math problem... The timer runs every 60 seconds (1 minute) and it adds time to variable "minutes". once it equals "cycletime" I want it to add some money to how much you've earned sofar. BUT variable "minutes" keeps going from there so I need a way to find out if minutes is divisible by cycletime. so assuming cycletime is 3 it pays every time minutes is 3, 6, 9, 12...ect



right now I tried using how much ive earned to calculate it but it messes up sometimes.
if (minutes/cycletime == made/makepercycle)


Make sure minutes is a "float"

if (minutes/cycletime == llRound(minutes/cycletime))
_____________________
Though this be madness, yet there is method in't.
-- William Shakespeare

Warburton's Whimsies:
In SL
Apez.biz
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
02-04-2008 23:26
Something like...

Multiplier = Time % Cycle;
PayAmount = Multiplier * Money;

...should do the trick quite nicely.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-04-2008 23:46
Instead of keeping track of some incremental sum, why not just keep track of starting time and use a straight function of the elapsed time? For example:

CODE

integer EARNINGS_PER_PERIOD = 4;
float PERIOD_SEC = 180.0; // 3 mintues
// ...
float startTime_sec = llGetTime();
// ...
float t_sec = llGetTime()-startTime_sec;
integer earnedMoney = EARNINGS_PER_PERIOD*llFloor(t_sec/PERIOD_SEC);