How can I change script dynamicly?

I need a function, the entity's deathscript is diffirent in different levels...
For example, I need something like this:
changeentityproperty(ent,"ondeathscript","data/scripts/death1.c");
Is the function available now ?
Or can I do it in a different way?
 
Code:
char branch = openborvariant("current_branch");

The above code will return the current level branch if one was set in levels.txt

declare branch example:
Code:
branch	branch_mountains_3
z	210 300 0 
file	data/levels/mountains/st03.txt

So just wrap this up in a if statement and your good to go.

Edit: another method would be to have a level update script detect when player dies but try to avoid update scripts as much as you can.
 
I have a better option: use a levelscript (which triggers just one time per stage) to set a global variable as the stage name.

Then just check for this variable in you ondeathacript and its done. No need to.use multiple scripts.
 
Sorry but your solution is the same as mine but with a extra step.  If you can already get the current branch from the engine why store it in a global variable ?
 
msmalik681 said:
Sorry but your solution is the same as mine but with a extra step.  If you can already get the current branch from the engine why store it in a global variable ?
Allow me to disagree with you.
No, they aren't the same. Your solution takes the current "branch", while mine identifies the current stage.

See this:
branch branch_mountains_3
z 210 300 0
file data/levels/mountains/st03.txt
z 210 300 0
file data/levels/mountains/st04.txt
z 210 300 0
file data/levels/mountains/st05.txt

Using your solution, it will return "branch_mountains_3" in all 3 stages, unless you set a branch for each stage (which IS a extra step).
There is a stagenumber in openbor but, as the manual explains, it can get inconsistent to real progress.

This is how I use:
My version uses a levelscript (or you can paste as a spawnscript of a empty entity)
Code:
@script
void main()
{
     void stageName;
     if (!stageName){
     setglobalvar("stageName","Sky Stage");
     }
}
@end_script

So, when I want to check for a stage name, i just paste this:
Code:
void stageName = getglobalvar("stageName");
if (stageName == "Sky Stage"){
*INSERT YOUR LOGIC HERE*
}

And just to avoid issues, I free the globalvar in endlevel.c (and I duplicate it into "ondestroy" at updated.c
Code:
void main()
{
   setglobalvar("stageName",  NULL());
}

With my method, I have far more control and flexibility. Since I can even change the stage name on the fly.

In programming, it does not matter if a method uses more steps (pure and simple talking), it matters their effectiveness. Some solutions may use more steps but work better.

 
I see I was thinking of how i would make the script as I always declare branch names maybe openbor should have a way to properly identify the stage like with the stage  text file name.
 
Back
Top Bottom