Re: A possible sound loading bug
Status: Alpha
Brought to you by:
cwalther
From: Christian W. <cwa...@gm...> - 2010-12-11 19:30:50
|
> I think I may have a bug, as the problem doesn't seem to be my code, > but maybe it is. > All I'm doing is playing a random short sound(3-5 seconds long) at a > controlled random interval, with 16 possible sounds to choose from. > The output tells me that the "sound" in the scheduled function "is a > nil value". > The function module is attached. This is not a bug, but intended behavior. The node description statements like "sound {...}", "cubic {...}", "hotspot {...}" etc. are only defined during node loading and undefined (nil) otherwise. You shouldn't think of them as functions, even though they technically are, but as declarative statements that are only used at the outermost level of node.lua, not in your own functions. To load a sound in your own code, use the pipmak.loadsound() function. (See also the footnote about it in the manual.) It would be more efficient to load each sound only once (as part of the node using a "sound {...}" statement, or on demand using pipmak.loadsound()) than every time it is played (unless you need to play the same sound file multiple times concurrently), but in your case that probably doesn't matter much. Also, "sfx_amb1_rand:play()" should probably be "sfx_amb1:play()". I wonder if it would be a good idea, instead of resetting the node description statements to nil after node loading, to set them to a function that prints a more helpful error message. -Christian |