Linking to script parts and more... (SOLVED)

Started by Hans, Thu 05/04/2007 10:42:01

Previous topic - Next topic

Hans

I have a script.

If (something1 happens){do 1
}
If (something2 happens){do 2
}
else {do 3}

This DOES work, BUT: as you can see, if something1 happens the script will continue and check if something2 happens.
How I want it:
If something1 happens I don't want the script to check if something2 happens.
If something1 doesn't happen I want the script to check if something2 happens.

I can use "else if", but is there a way to LINK to another part of a script?

And I also forgot how to change the speech view. How did you do that?

SSH

Why don't you want to use "else if"?

And what do you mean by linking? If you have repeated code, you can make a function and call it...
12

monkey0506

Okay, the simplest solution would probably just be to use else if as you've said, but as for linking to another part of a script, it sounds like perhaps you want to write your own function?

Code: ags
function my_func_1() {
  // do stuff 1
  }

function my_func_2() {
  // do stuff 2
  }

// inside other function
if (something_1) my_func_1();
else if (something_2) my_func_2();
// etc.


When you define your own function you're defining a code snippet that you can call from anywhere else in your script. It's particularly useful if you need to perform the same function multiple times throughout your scripts. I could go into exporting/importing functions and more in-depth details, but I'm not entirely sure this is what you want.

Feel free to ask if you have any further questions, and do let me know if this is even remotely what you meant. :)

SSH you n00b posted before me.

Hans

#3
I want to change the players view if something1 happens. But i want to change the idle- and speechview along with it.
I want something1 to change the view back if it is already changed.

How do i do that?

monkey0506

#4
Code: ags
if (something_1) {
  player.ChangeView(5);
  player.SetIdleView(8, GetGameSpeed() * 5); // wait 5 seconds before playing the idle animation
  player.SpeechView = 11;
  }
else if (something_2) {
  player.ChangeView(6);
  player.SetIdleView(9, GetGameSpeed() * 5);
  player.SpeechView = 12;
  }
else if (something_3) {
  player.ChangeView(7);
  player.SetIdleView(10, GetGameSpeed() * 5);
  player.SpeechView = 13;
  }


Like that?

-You're wanting to *change* the player's view, not just temporarily animate it, right? That would be ChangeView not LockView.-

It's called reading the manual. It's something I didn't do. That's why there weren't enough parameters in Character.SetIdleView. ;P

SMF spam blocked by CleanTalk