Help - Search - Members - Calendar
Full Version: Raising Whole Numbers To A Power
SphereServer Forums > Sphere .55i - Discontinued > FUNCTION & EVENTS Script Submissions .55i
Maximus
I was bored so I wrote this biggrin.gif

Usage: .exp 2 5
calculates 2 to the 5th power

Exponent cannot exceed 5

If anyone thinks of a way to get this to work without exponent restrictions, then please let me know!

CODE
[function exp]
local.x = <eval <strarg <args>>>
local.exp = <eval <streat <args>>>
if (<local.exp> == 0) || !<local.exp>
message 1
return 1
elif (<local.exp> == 2)
CALL exp2
elif (<local.exp> == 3)
CALL exp3
elif (<local.exp> == 4)
CALL exp4
elif (<local.exp> == 1)
message <eval <local.x>>
return 1
elif (<local.exp> == 5)
CALL exp5
else
sysmessage The exponent cannot exceed 5
return 1
endif

[function exp2]
local.final = <eval <local.x> * <local.x>>
message <eval <local.final>>
return 1

[function exp3]
local.temp = <eval <local.x> * <local.x>>
local.final = <eval <local.x> * <local.temp>>
message <eval <local.final>>
return 1

[function exp4]
local.temp = <eval <local.x> * <local.x>>
local.temp2 = <eval <local.temp> * <local.x>>
local.final = <eval <local.temp2> * <local.x>>
message <eval <local.final>>
return 1

[function exp5]
local.temp = <eval <local.x> * <local.x>>
local.temp2 = <eval <local.temp> * <local.x>>
local.temp3 = <eval <local.temp2> * <local.x>>
local.final = <eval <local.temp3> * <local.x>>
message <eval <local.final>>
return 1
Maximus
I always forget to specify the version... 55r3rc3
Baube
QUOTE (Maximus @ May 1 2004, 05:44 PM)
If anyone thinks of a way to get this to work without exponent restrictions, then please let me know!

Hello! my name is JyzJmz
CODE

[FUNCTION exp]
local.number = <strarg <args>>
local.number1 = <local.number>
for <eval <streat <args>>+-1>
   local.number *= <local.number1>
endfor
return <local.number>
SephDragoon
or my version (sorry, gotta write one... shortest one wins).

[FUNCTION EXPO]//I renamed, because some people may have an EXP as in level system, like me.
LOCAL.NUMBER=1
FOR <eval <ARGN2>>
LOCAL.NUMBER=<eval <LOCAL.NUMBER>*<ARGN1>>
ENDFOR
RETURN <eval <LOCAL.NUMBER>>
Baube
QUOTE (SephDragoon @ May 1 2004, 08:11 PM)
or my version (sorry, gotta write one... shortest one wins).

[FUNCTION EXPO]//I renamed, because some people may have an EXP as in level system, like me.
LOCAL.NUMBER=1
FOR <eval <ARGN2>>
LOCAL.NUMBER=<eval <LOCAL.NUMBER>*<ARGN1>>
ENDFOR
RETURN <eval <LOCAL.NUMBER>>

Hey man, you used too many "eval's" wink.gif

I win unsure.gif
SephDragoon
mine is less lines, and I used ARGN1/2 which doesn't take up much compared to STREAT and STRARG rolleyes.gif.
Tattooed_Corpse
OK here we go again posting revisions of other people's submissions....
mad.gif
Baube
[FUNCTION EXPO]//I renamed, because some people may have an EXP as in level system, like me.
LOCAL.NUMBER=1
FOR <eval <ARGN2>> // Used one time
LOCAL.NUMBER=<eval <LOCAL.NUMBER>*<ARGN1>> // Used 6times
ENDFOR
RETURN <eval <LOCAL.NUMBER>> // Used one time // Total:8





[FUNCTION exp]
local.number = <strarg <args>>
local.number1 = <local.number>
for <eval <streat <args>>+-1>
local.number *= <local.number1>
endfor
return <local.number>


Mine have a total of 3 "Useless things"
so the best thing would be:
CODE

[FUNCTION exp]
argn3 = 1
for <argn2>
argn3 *= <argn1>
endfor
return <argn3>




Btw, my first function was only to help maximus because he's friend
And my other was to compete SpehDragoon because he's nice... hehe
SephDragoon
QUOTE (Tattooed_Corpse @ May 2 2004, 02:37 AM)
OK here we go again posting revisions of other people's submissions....
mad.gif

QUOTE (Maximus @ May 1 2004, 10:44 PM)
If anyone thinks of a way to get this to work without exponent restrictions, then please let me know!


He kind of asked yah know.
Maximus
lol.... this is amusing
Maximus
Yeah earlier today, i was trying to figure out how to use a FOR loop, because thats what first came into my head, but i never figured it out, lol... and Tattooed, I did ask for help along with a submission, so it should be ok.
Tattooed_Corpse
Well then post this in scripting help! This is for completed scripts...or did you forget to read that part?
Baube
He posted a complete script.
He knew his script wasn't perfect but it still do the job.
We helped him.

There is nothing bad about it.
Tattooed_Corpse
QUOTE (Baube @ May 2 2004, 04:24 PM)
He posted a complete script.
He knew his script wasn't perfect but it still do the job.
We helped him.

There is nothing bad about it.

What is Bad about it is that people are having responsive threads on forum script submission section.
Please don't dispute this.
If it isn't ready then don't post a submission with a request.
I know you think I'm poking my nose and maybe I am, but it's all for the sake of clarity in the Submission Section.
I won't back down on this issue...
Period.
SephDragoon
In other words... don't reply anymore and bump the thread up... (for those who don't know what it means). There are problems with that... so I hope this one clarifying the last one will be the last one... erm, yeah.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.