 |
Castle Paradox
|
| View previous topic :: View next topic |
| Author |
Message |
Uncommon His legend will never die

Joined: 10 Mar 2003 Posts: 2503
|
Posted: Tue Apr 19, 2005 11:31 am Post subject: |
|
|
| Well, npc references are faster than ID's anyway. |
|
| Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Tue Apr 19, 2005 5:44 pm Post subject: |
|
|
General tip for speeding up npc commands : store and use npc references rather than using npc ids. This doesn't apply for all npc commands though.
Also, NPC at spot is slow. It loops through all 300 possible npcs, checking if any of them are at the spot.
| Quote: | A very hearty thanks to the Mad Cacti for the wealth of information he provided. I have only one question about your response: you said that
| Quote: | | Reading/writing globals, generating random numbers, and map operations are likely to be all roughly as long. |
|
I meant that any old command is about as fast as any other command. Most commands don't run time consuming loops or other things, and are on even ground because the interpreter does other stuff besides executing them. All are far faster than alter npc.
OK, I need to stop for a second and say that these sort of optimisations (the following, not using alternpc is always good advice) are pointless unless your script is already running really slowly from doing something slow dozens of times per tick, otherwise, you won't notice a thing, and still might not, and your 'optimisation' is really superstition. Again, most commands aren't slow, Hamsterspeak is.
As for not passing dozens of arguments to scripts, yes, thats true, but consider
| Code: |
global1 := something1
global2 := something2
global3 := something3
global4 := something4
global5 := something5
my script
|
vs.
| Code: |
my script (something1, something2, something3, something4, something5)
|
There is no gain (probably the opposite) in the first, because you have to set all those globals. On the otherhand, if the 'something's were or could be stored in globals the whole time, keep them in globals, and that's better.
I often use a bunch of math over lots of if's, but I do it mostly because I think its prettier, I'm not sure if it's any faster. Doing all those math operations is likely to slow down your script just as much, unless it would otehrwise require lots of ifs. However, if you have a really huge bunch of if commands, I can give you a good optimisation.
Consider
| Code: |
var := random (1, 16)
if (var==1) then (..1)
if (var==2) then (..2)
if (var==3) then (..3)
if (var==4) then (..4)
if (var==5) then (..5)
if (var==6) then (..6)
if (var==7) then (..7)
if (var==8) then (..8)
if (var==9) then (..9)
if (var==10) then (..10)
if (var==11) then (..11)
if (var==12) then (..12)
if (var==13) then (..13)
if (var==14) then (..14)
if (var==15) then (..15)
if (var==16) then (..16)
|
This is going to be slow if it's long or called often : 16 ifs, 16 conditionals, and 16 then/elses executed (they exist, and are empty even if not specified).
A good improvement (and getting better the more ifs there are, is... not pretty, but:
| Code: |
var := random (1, 16)
if (var<=8) then (
if (var<=4) then (
if (var==1) then (..1)
if (var==1) then (..2)
if (var==1) then (..3)
if (var==1) then (..4)
) else (
if (var==1) then (..5)
if (var==1) then (..6)
if (var==1) then (..7)
if (var==1) then (..8)
)
) else (
if (var<=12) then (
if (var==1) then (..9)
if (var==1) then (..10)
if (var==1) then (..11)
if (var==1) then (..12)
) else (
if (var==1) then (..13)
if (var==1) then (..14)
if (var==1) then (..15)
if (var==1) then (..16)
)
)
|
Now its 6 if's, conditionals, then/elses. If you needed, say, a sine lookup table with 90 if's, this is invaluable. _________________ "It is so great it is insanely great." |
|
| Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Wed Apr 20, 2005 3:06 am Post subject: |
|
|
Okay, this could be very key for me. It sounds like if the NPCs that I want to alter (but not by alternpc) are all placed by custom, then their references will be in order, and will NOT change even if I use 'change NPC ID'. Thus I can use a 'for' loop to tell all of these NPCs what to do, where the index being incremented (or decremented, since I will be using a negative index, apparently) in the 'for' loop is used for the reference number of the NPC (I'm assuming that HS has a backwards NPC reference type command). Is this all correct?
By the way, this optimisation is very important to me. Right now I have 36 alter npc commands trying to take place at once, 18 changing picture and 18 changing palette. |
|
| Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Wed Apr 20, 2005 4:43 am Post subject: |
|
|
That's right.
The opposite to 'npc reference' is 'get npc id', but you won't be needing it. _________________ "It is so great it is insanely great." |
|
| Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Wed Apr 20, 2005 6:13 am Post subject: |
|
|
| I just wanted to thank everyone who took the time to offer information and suggestions. I will try optimising my script according to these ideas to speed it up, and it seems like it should work. But quite apart from this script, I believe that I have learned some invaluable information about the hamsterspeak language, and general plotscripting, as well. Thanks again. |
|
| 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
|