Hello!
I would like to ask if you would have done it exactly the same way or if you know a better way for the following situation:
I have designed a new "Tinycritter" and I want it to play a sound at random intervals.
For this I gave the Critter class = "Timer" and configured this Timer with the following "OnInit" script:
Code: Select all
onInit = function(self)
self.go.sound:disable()
self.go.critterbrain:setSource("function randomintervals(sender)local random = math.random(5,15)sender.go.timer:stop()sender.go.timer:setTimerInterval(random)sender.go.sound:play("critterattention")sender.go.timer:start()end
self.go.timer:setTimerInterval(15)
--self.go.timer:addConnector("onActivate", "critterscript", "randomintervals")
self.go.timer:addConnector("onActivate", "self? sender?", "randomintervals")
self.go.timer:setCurrentLevelOnly(true)
end,
The Timer calls the following script: Edit2: (not anymore)
Code: Select all
function randomintervals(sender)
local random = math.random(5,15)
sender.go.timer:stop()
sender.go.timer:setTimerInterval(random)
sender.go.sound:play("critterattention")
--playSoundAt("critterattention", sender.go.level, sender.go.x, sender.go.y)
sender.go.timer:start()
end
Well, I don't know, is that the best way to reach the goal? It works, but I feel like there's a better way! A Sound class with a cooldown would be nice but I didn't find any information about it in the Wiki
https://github.com/JKos/log2doc/wiki/Class-list
Edit: I have now added a Sound class and call sender.go.sound:play("critterattention") instead of playSoundAt.... this way the Sound "goes" with the fleeing Critter! Can I also add a Script Class and fill this script? Hmm...
Edit2: Okay, so I added a Script class and filled it with the Script. I can run the script with the console but not with the Timer! Typing in Console: testcritter.critterbrain:randomintervals() works but the Timer says: "warning! invalid connector target: self.go.critterbrain" 'self.go' don't work, 'self' don't work, 'sender.go' don't work and 'sender' don't work... Hmm...
I am open for every idea! So thanks for reading and happy Holidays!
