Page 1 of 1
100 of bottles of bear...
Posted: Tue Sep 24, 2002 11:23 am
by garazdawi
nay know how to make a script that make an NPC sing one "hundred of bootles of bear on the wall, you take one..." and so on. nayone? been trying for ages
BTW if possible avoid using heartbeat
Posted: Tue Sep 24, 2002 4:30 pm
by Xyx
In the onSpawn script, make a function that sings the line and calls itself again after a few seconds (using DelayCommand). Call that function from the main() and of you go.
Posted: Wed Sep 25, 2002 9:52 am
by garazdawi
Originally posted by Xyx
In the onSpawn script, make a function that sings the line and calls itself again after a few seconds (using DelayCommand). Call that function from the main() and of you go.
I tried to put a while loop that did what you said but using recursion migt be a good way to do it. I'll check it out. When using the while loop I got a TMI

Posted: Wed Sep 25, 2002 12:22 pm
by lunarwater
I would suggest staying away from recursion because it will slowly fill up your memory after a while (if it does nothing but call itself and never return). The servers stack may start to blow chuncks eventually. My suggestion would be to rethink the while loop idea in conjunction with the DelayCommand.
Another way to do this is to create a user defined event. In the on spawn Delay a triggering of that event. Then in the main() of the event, have your bear singing code and at the end a delayed triggering of the event all over again. This way each funtion should finish up.
Posted: Wed Sep 25, 2002 5:15 pm
by Xyx
How does this work? An event is nothing more than just another function, isn't it? Why would you not recurse when using an event?
Posted: Wed Sep 25, 2002 5:40 pm
by lunarwater
Aren't the events simply handled similar to signals and interrupts? I could be wrong, because I do not know biowares underlying framework. You define the different signals (or events) and then provide the code to execute when the interrupt is caught. My guess is the function that causes an event to take place simply takes the constant that you pass in (the event variable) and then triggers this. However, like I said, Bioware could have a different implementation, in which case i would suggest the looping method.
Posted: Thu Sep 26, 2002 8:26 am
by garazdawi
Posted: Thu Sep 26, 2002 1:08 pm
by lunarwater
All I wanted to say was just a warning against using recursion with something that may go on infinitely (or until the server crashes, reboots). If the beer song ends after 100 repetitions, then disregard my posts. If not, then what I was trying to say is that if function a() calls function a(), so much memory is used for each time the function gets called (for local variables, return location, etc..). Once the function a() calls itself too many times, the system will not be able to allocate any more memory to the process and crash. Somehow, you would have to program a function that does not continuously need more memory at each iteration w/o freeing it. As for the specifics of the scripting language, I am still learning myself. I do know, however, that every recursive call can be rewritten using looping (and every loop can be rewritten using tail recursion). Sorry for any confusion. I think I've successfully done more bad than good... Good luck at any rate.
Posted: Thu Sep 26, 2002 10:54 pm
by Xandax
lunawather: you are correct, speaking from a programmers perspective, that one needs to be carefull with recussion *iff* it doesn't return something(or a condition are made that breaks the method), then it will countinue endlessly as a neverending loop requiering more and more memory
So I think your warning is justified
I don't know much about NwNScript though, so can't really help you there

(although I could program this in my sleep in Java

)
Posted: Fri Sep 27, 2002 11:26 am
by garazdawi
Originally posted by Xandax
I don't know much about NwNScript though, so can't really help you there
(although I could program this in my sleep in Java
)
Me to but in pascal that is. I didn't quite get my mind about the nwn script language yet but i'm learning it quite fast so in a couple of weeks I'll probably manage this scrit quite easy but as things are now....
I haven't had the time to check any of your suggestions yet (busy programming by comp project for school) I'll try it out a.s.a.I.h.t. (as soon as I have time

)
Posted: Fri Sep 27, 2002 6:55 pm
by Xyx
I tried a couple of things. Regular recursion gives a stack overflow error almost instantly.
Using the user defined event did not cause the stack error but froze my machine. Maybe it would have given me the stack error if I waited two days, but I didn't. Not sure if that means it uses recursion or not. It certainly didn't try to execute any of the floating text code until after it was finished. I know because I once capped it off at 100 iterations and got 100 floating strings during the next five minutes.
