some scripting tricks I've come across

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: some scripting tricks I've come across

Post by Grimwold »

Excellent post cromcrom. Thanks.


Also I've just updated my original post with the following:

Add multiple tests to the same hook
With so many spells and effects using party, monster or other hooks, it can happen that you need to run two different scripts as part of the same hook. This can be done by evaluating each script as a variable and then returning both.

Code: Select all

    onTurn = function(monster,turn_dir)
      local hold_test = grimwold_spell_script.checkHeld(monster)
      local turn_test = grimwold_spell_script.checkTurn(monster,turn_dir)
      return hold_test and turn_test
    end,
here we first evaluate the checkHeld() function which will run a script and output either true or false. then we evaluate the checkTurn() function which will run another script and again output either true of false. Finally we return the AND of the outputs.. so if either (or both) output is false the overall output will be false and the monster will not execute its turn. If both are true, the monster turns.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: some scripting tricks I've come across

Post by Komag »

nice! I too am starting to see cluttered party hooks, so I'm sure this will be useful
Finished Dungeons - complete mods to play
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: some scripting tricks I've come across

Post by trancelistic »

I know I'm 3 years behind then others, But I still wanna learn. I Saw your 1-13 script and I guessed right away what it did while others didnt. ( So I got to have some minor intelect haha)
But my question is about an ID. If a script can spawn ( via a script) .. lets say some things on the map... like spawn 5 times the item "dagger".

how would a script know how to spawn (x) dagger ( as x stand for 1 to 999 daggers) but at te same time ( or later by a timer) it will :destroy then 0 to 999 dagger ( items) in the game.

Because so far i've learned. I can only destroy a full IDname.

I hope i make sense somewhere:(

I'm still trying to learn..


..Can some 1 give me an exsample if a script spawns 5 x the same dagger item, but each 1 tile away. So i got, as a partry, seeing a dagger each step i take.

but then a destory script takes them all out ( but to me it only works if i know the ID:destroy() else the game crashes...


I Know how to do this if i Name each item with its own ID, so i can destroy that ID. But I saw scripts spawning nummers of the same item and it destroys them too..( without the game crashing with the error : Id not found...

Meh I hope I make sense:P
Post Reply