 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sat Aug 09, 2003 1:21 pm Post subject: Speed issues... |
|
|
Does anyone have any good tips for speeding up scripts?
Does anyone know whether the increment()/ decrement() are any faster than writing
x := x + y
? Thinking about it, it seems logical that it would be faster, as the PS interpreter only does one command instead of 2. Though I don't think I've ever used a decrement or increment command in any of my scripts ever.... :S _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Blazes Battles Inc. I'm a chimp, not a
Joined: 25 Jan 2003 Posts: 505
|
Posted: Sat Aug 09, 2003 4:46 pm Post subject: |
|
|
I doubt it's noticably faster. I have a script with about ten thousand of those set variable commands that barely takes an instant to finish. Is the script actually working slowly, or are you just planning ahead? _________________ Preserve OHR history! Do it for the children! |
|
Back to top |
|
 |
Inferior Minion Metric Ruler

Joined: 03 Jan 2003 Posts: 741 Location: Santa Barbara, CA
|
Posted: Sat Aug 09, 2003 9:40 pm Post subject: |
|
|
When it comes to analyzing scripts, it's standard practice to treat all assignment commands as taking the same time. The real meat of the runtime is caused by loops and whatnot.
I'm not sure if this will help at all...but it's the lecture notes from my Comp. Sci. class on Analyzing Algorithm Runtimes...Here's the lecture and here are the notes for filling in the blanks. The way the class was conducted, the teacher would use the first sheet and a projector for lecture. We could download/print the lecture before hand and fill in the blanks as he went along. He would then put the second page online a week or so later.
Hopefully it's useful to someone  _________________
|
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sun Aug 10, 2003 3:31 am Post subject: |
|
|
Well, thanks, I'll have to read through all of that..
I'm planning in advance, I'm sure my script is going to run really slow, having alot of compund loops, recursing, and npc intructions..
Code: | it's standard practice to treat all assignment commands as taking the same time |
I meant the difference in speed between interpreted Plotscripting instructions, and instructions coded into game.exe _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
planethunter Lost In Emotion

Joined: 07 Jul 2003 Posts: 258 Location: Éire
|
Posted: Sun Aug 10, 2003 11:44 pm Post subject: |
|
|
the only "good" thing about using the increment and decrement commands
is that instead of the compiler assessing both variables and adding, it just
assesses one and adds...
But! doing so would probably just increase the "speed" by 0.0000000001%
It really makes no odds what you use. the X: x+y thing is only useful if
you use changing variables. ( I dislike saying variable variables)
That aside you should just keep it simple, and use de/increment commands.
phew! _________________ ~PH
 |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Mon Aug 11, 2003 10:23 pm Post subject: Speed |
|
|
Yes, theoretically, increment(V) ought to be just slightly faster than V:=V+1 , but the difference is so incredibly small that you should not care.
The slowest commands are the ones that affect NPC's, In particular, any command that uses an NPC ID is guaranteed to be slow. Use NPC references wherever possible. For example, suppose you want to write a script that checks every NPC to see whether or not it is standing within 4 blocks of the hero
Code: |
variable(ID)
for(ID,0,35)
do,begin
if(NPC X(ID) >= hero X (me) -- 4,and,NPC X(ID) <= hero X (me) + 4,and,NPC Y(ID) >= hero Y (me) -- 4,and,NPC Y(ID) <= hero Y (me) + 4)
then,begin
# do special stuff for close-by NPCs
end
end
|
This example will be super slow, because for every NPC ID it runs four commands that use the NPC ID. (NPC X twice and NPC Y twice). You can cut the speed of this script to almost a quarter by using an NPC reference.
Code: |
variable(ID,ref)
for(ID,0,35)
do,begin
ref:=NPC reference(ID)
if(NPC X(ref) >= hero X (me) -- 4,and,NPC X(ref) <= hero X (me) + 4,and,NPC Y(ref) >= hero Y (me) -- 4,and,NPC Y(ref) <= hero Y (me) + 4)
then,begin
# do special stuff for close-by NPCs
end
end
|
Now you only have to use the NPC ID in one single command (NPC reference) so the script will not have to re-look-up the NPC each time you use NPC X and NPC Y.
This applies also to Walk NPC, NPC Direction, set NPC direction, Create NPC Destroy NPC, and almost anything else that can use an NPC ID number ("Alter NPC" being the exception, It goes about the same speed whether you use an ID or a reference)
Another way to keep scripts fast is to only loop as much as you really need to. Take the previous example again. Suppose you want to check for NPCs within 4 spaces of the hero, and do something special for them, but you know that you have only actually created twelve NPCs on this particular map.
Code: |
variable(ID,ref)
for(ID,0,11)
do,begin
ref:=NPC reference(ID)
if(NPC X(ref) >= hero X (me) -- 4,and,NPC X(ref) <= hero X (me) + 4,and,NPC Y(ref) >= hero Y (me) -- 4,and,NPC Y(ref) <= hero Y (me) + 4)
then,begin
# do special stuff for close-by NPCs
end
end
|
just change the "for" so you only loop as much as you need to. |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Thu Aug 14, 2003 1:24 pm Post subject: |
|
|
Even create NPC? I never knew that... but I did know to avoid npc functions..
well, thanks for the help! _________________ "It is so great it is insanely great." |
|
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
|