 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Rinku

Joined: 02 Feb 2003 Posts: 690
|
Posted: Sun May 15, 2005 1:17 am Post subject: log function |
|
|
does anyone know how to simulate the log function in integer math like the ohrrpgce uses? for example, would something like this work?
script, log, value, base
(
# RETURNS THE INTEGER LOG 'value' IN BASE 'base'.
# DEFAULT BASE IS 10.
if ((n / base) >> 1) then (return (1))
if (((n / base) / base) >> 1) then (return (2))
if ((((n / base) / base) / base) >> 1) then (return (3))
# etc.
) _________________ Tower Defense Game |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sun May 15, 2005 4:06 am Post subject: |
|
|
My 'math.hss' file is getting so large.
Code: | define script (-1, log, 2, 0, 10)
script, log, value, base, begin
variable (result)
while (value >= 1) do (
value := value / base
result += 1
)
return (result -- 1)
end |
Always rounds down. What use is this script, you ask? log of a number to base 10 + 1 returns its length in digits, possibly useful when displaying numbers.
(rinku, ignore the difference in scripts) |
|
Back to top |
|
 |
Rinku

Joined: 02 Feb 2003 Posts: 690
|
Posted: Sun May 15, 2005 5:16 am Post subject: |
|
|
that should work.
btw, you should release math.hss with quaternion!
better: we should have a public place to post general-use scripts, and they'd be auto-added to new versions of the ohrrpgce. i could include the best script ever, maybe. here's the simplest version of it.
script, maybe
(
if (random (0,1) then (return (1)) else (return (0))
)
it's amazingly useful! you can do things like
maybe + maybe + maybe and get a weighted random number between 0 and 3, but it'd much more often be 1 or 2 than 0 or 3.
also useful for if (maybe) then (do something) for something that should happen half of the time. every game should have a maybe! _________________ Tower Defense Game |
|
Back to top |
|
 |
Cube Dimensional Traveller

Joined: 02 Feb 2003 Posts: 294
|
Posted: Sun May 15, 2005 1:12 pm Post subject: |
|
|
Hmm, that might be an interesting new addition to the CP update (The script uploading idea, that is). I thought about it before in the past, but totally forgot until now . It'd be nice if there was a library that the community can freely contribute to.
But also, a while back I created a chance script that's used in a similar way as that maybe script. It's actually part of that library I have posted as a sticky. But instead of just being true or false, it would return true based on a percentage. I dunno if you'd use it or not, but you never know:
Code: |
script, Chance, CPercent, begin
if ((random (1, 100)) <= CPercent, and, CPercent <> 0) then (
return (true)
) else (
return (false)
)
end
|
So you could have something happen 67% of the time if you wanted it to.
For that maybe script too, you could just shorten it to simply this:
Code: |
script, maybe
(
return(random(0, 1))
)
|
Since you're just returning the numbers created by the random function in the first place
But yeah, I'll talk to IM about adding a plotscripting section itself to CP somewhere. Script sharing is always fun . |
|
Back to top |
|
 |
Mike Caron Technomancer

Joined: 26 Jul 2003 Posts: 889 Location: Why do you keep asking?
|
|
Back to top |
|
 |
Rinku

Joined: 02 Feb 2003 Posts: 690
|
Posted: Mon May 16, 2005 4:06 am Post subject: |
|
|
i do have a percent-based version of maybe, which works much like the one you posted (the default value for the percent is 50). it's pretty useful too. _________________ Tower Defense Game |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|