No worries - I'll explain what's going on, as this is a really useful technique for building big dungeons and not having to repeat code over and over. Then I'll explain how to fix the problem (although, you should be able to fix it yourself then!).
So, when you place a script entity into your dungeon, you can access the global values and functions in that script entity from any other script entity in the game. You do this by putting "[other_script_entity_id].[variable]" or "[other_script_entity_id].[function]()". For example, if you had a script_entity with the name "useful_functions" and you have a function in that called "hello_world" you could call that from any other script. This doesn't do anything useful, but would look like...
SCRIPT ENTITY: useful_functions
Code: Select all
With the above in your dungeon, any other script entity can call that method by doing the following...
Why this works, is because the bit before the dot (.) is actually looking through your dungeon for another object with the same name. Because you have already made a script entity called 'useful_functions', it finds that script entity. Then you have called the function 'hello_world' on that script_entity, which exists - so it will run.
Now, in the solution I provided I suggest making a script_entity specifically called 'utils' and putting the code in there. This is a good place to put generic functions that you might want to use from anywhere in the dungeon, over and over. For instance, you might want to spawn a grid of objects in a few places - that's why I wrote a generic solution that you could use over and over (even in different dungeons).
So, the steps to getting this to work in your dungeon when you push a button say is the following...
1. You need to make a script_entity called 'utils' and put the code above in it. Functions in this script are useful across the entire dungeon - however, because you need to pass them parameters to get them to work, you can't call them directly from levers. So...
2. You will then need to make a second script_entity called 'level1' say (whatever you like really, but the idea is that you could put all of your traps into one script so that you can keep track of them.
In this second script, I would put something like the following;
Code: Select all
utils.spawn_grid("posion_cloud", 3, 4, 6, 7, 6, 1);
Note that this works because you have already made a script_entity called 'utils' with the method 'spawn_grid' in it.
3. Now hook the button / lever up to the 'level1' script and the 'poisonProba' function.