Ask a simple question, get a simple answer
Re: Ask a simple question, get a simple answer
Thx guys. I was trying to seed it with os.time(), but like minmay said, i can't use it...
Anyways great explanation. Just one thing to add there. math.randomseed() only accepts integer values, so if you use math.randomseed(Time.systemTime()), you should multiply the Result of Time.systemTime() with 1000, since it returns the time resolution up to milliseconds, otherwise it's not very effective when running it on a loop, like in my case.
Anyways great explanation. Just one thing to add there. math.randomseed() only accepts integer values, so if you use math.randomseed(Time.systemTime()), you should multiply the Result of Time.systemTime() with 1000, since it returns the time resolution up to milliseconds, otherwise it's not very effective when running it on a loop, like in my case.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
Yep.....moving on!
Re: Ask a simple question, get a simple answer
Does removeConnector actually work for connectors to the onDrawGui hook?
(Because it never seems to for me. I can create party component connectors to it, but can never remove them.)
(Because it never seems to for me. I can create party component connectors to it, but can never remove them.)
-
- Posts: 24
- Joined: Sat Nov 26, 2016 12:12 pm
Re: Ask a simple question, get a simple answer
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:
The Timer calls the following script: Edit2: (not anymore)
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!
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,
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
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!
Last edited by ColdDeadStone on Fri Dec 22, 2017 5:29 pm, edited 3 times in total.
Sorry for my poor english... hope you understand what i try to say!
Re: Ask a simple question, get a simple answer
ColdDeadStone: I am curious what kind of critter did you make (new animations etc?) and how did you do it? / and will you share it with the community ?
Re: Ask a simple question, get a simple answer
Hey ColdDeadStone,ColdDeadStone wrote:The Timer calls the following script: Edit2: (not anymore)SpoilerShowCode: 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,
SpoilerShowCode: 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
I suspect the issue (and solution) involves one of these:
1. The order in which you have added components to your TinyCritter Object (this can be an issue)
2. The timer's onInit Hook not triggering when you start up the preview
( I remember someone having dramas with firing their onInit hooks - but I cant for the life of me recall who or where the thread is)
3. Perhaps try adding a ScriptController component to the critter object
4. Maybe try :
self.go.timer:addConnector("onActivate", self.go.id, "randomintervals")
...or
self.go.timer:addConnector("onActivate", self.go.critterbrain, "randomintervals")
EDIT ^^^ this might be the best place to start
Also, this may help...
viewtopic.php?f=22&t=7951&p=110822&hilit=onInit#p110822
Sorry I cant be more precise
Quick reply before heading off to work - hope you solve it!
Akroma
Labyrinth of Lies (viewtopic.php?f=14&t=4400)
Legacy of Lies (viewtopic.php?f=22&t=12983&hilit=+legacy)
Legacy of Lies (viewtopic.php?f=22&t=12983&hilit=+legacy)
-
- Posts: 24
- Joined: Sat Nov 26, 2016 12:12 pm
Re: Ask a simple question, get a simple answer
Code: Select all
self.go.timer:addConnector("onActivate", "self.go.id", "randomintervals")
self.go.timer:addConnector("onActivate", "self.go.critterbrain", "randomintervals")
self.go.timer:addConnector("onActivate", "sender.go.id", "randomintervals")
self.go.timer:addConnector("onActivate", "sender.go.critterbrain", "randomintervals")
It would be nice to have everything already in the "defineObject" but actually it doesn't matter anyway since the critters belong to a side quest and you can "collect" them. That again calls a "script_entity" in the dungeon anyway, so I can do this with the Sound also "externally". It works externally in any case.
All well so far! I just thought there might be a better way but as I said before, my way is no problem because the critter at "onClick" calls a script in the Dungeon anyway!
Thanks for reading and your time too! Merry Christmas
@akroma222: I like your "punk alice" avatar btw
Edit: I forgot to mention that I changed the order of the components... Timer, Script, ScriptController etc. in different sequences! But nothing worked. I start the "onInit" script mostly from the Model Component and had no problems with it so far! Connecting the Timer with a "script_entity" is also no Problem.
Sorry for my poor english... hope you understand what i try to say!
Re: Ask a simple question, get a simple answer
Ohh, the 2nd argument for addConnector (target), in this case, doesnt need ""ColdDeadStone wrote:Code: Select all
self.go.timer:addConnector("onActivate", "self.go.id", "randomintervals") self.go.timer:addConnector("onActivate", "self.go.critterbrain", "randomintervals") self.go.timer:addConnector("onActivate", "sender.go.id", "randomintervals") self.go.timer:addConnector("onActivate", "sender.go.critterbrain", "randomintervals")
=> Try these {"self.go.id", "self.go.critterbrain", "sender.go.id", "sender.go.critterbrain"} without the " " (I cant spell parenthesis, but spellcheck can )
Code: Select all
self.go.timer:addConnector("onActivate", self.go.critterbrain, "randomintervals")
Hahah thanks - I held a Disney Disaster themed Party and to design the invites I googled up a bunch of princesses doing not so princessy thingsColdDeadStone wrote:@akroma222: I like your "punk alice" avatar btw
Labyrinth of Lies (viewtopic.php?f=14&t=4400)
Legacy of Lies (viewtopic.php?f=22&t=12983&hilit=+legacy)
Legacy of Lies (viewtopic.php?f=22&t=12983&hilit=+legacy)
Re: Ask a simple question, get a simple answer
Hello all,
is there a way to add a group of monster in a bossfight?
is there a way to add a group of monster in a bossfight?
Re: Ask a simple question, get a simple answer
Just add the monsters one by one the same way you would if they weren't in a group. You don't know their ids in advance, of course, but you can use Map:entitiesAt() to find them.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
hum,minmay wrote:Just add the monsters one by one the same way you would if they weren't in a group. You don't know their ids in advance, of course, but you can use Map:entitiesAt() to find them.
so
instead of doing it like that:
Code: Select all
spawn("medusa_2_xaafi_pair",45,15,5,1,0,"xaafiIngerence_8")
xaafiPremierBoss.bossfight:addMonster(xaafiIngerence_8.monster)
xaafiIngerence_8.monster:addConnector("onDie", "counter_39", "decrement")
SpoilerShow
Code: Select all
defineObject{
name = "medusa_2_xaafi_pair",
baseObject = "base_monster_group",
components = {
{
class = "MonsterGroup",
monsterType = "medusa_2_xaafi",
count = 2,
}
},
}
Code: Select all
spawn("medusa_2_xaafi",45,15,5,1,0)
spawn("medusa_2_xaafi",45,15,5,1,0)