Playing View Loop according to variables

Started by RenatoDias, Wed 28/11/2012 03:36:17

Previous topic - Next topic

RenatoDias

Hey guys, here is my question:
I have a certain loop that I want it to rely on a variable to play, for example:
If variable1=1, play View1's Loop 0; if variable1=2, play View1's Loop 1 and so on.
So, long story short, I would like to play the loops through scripting. Is it doable with AGS 3.2.1.111?(The build I have)
Also, when walking, will the Loops above 8 be played automatically?
PS: I know it may have been asked before, but, if you guys can answer this for me. If I'm asking on the wrong forum thread, please move and warn me by PM.
Thanks...

Icey

Code: AGS
If(variable1 == 0){
SoandSo.Animate(...);
}
else if(variable1 == 1){
SoandSo.Animate(...);
}


You never said what it is(character, object, button, etc...) that you wanna animate.

Crimson Wizard

#2
Quote from: icey games on Wed 28/11/2012 04:47:21
Code: AGS
If(variable1 == 0){
SoandSo.Animate(...);
}
else if(variable1 == 1){
SoandSo.Animate(...);
}
And if there are 100 options, there will be 100 else ifs. :)

This is indeed a generic question, in the meaning it does not apply to loops in particular. It is about using parameters. In the case described above, you want to use a function based on parameter to calculate loop. Basically Loop = (param - 1).
If everything else is always the same, you may just write this:

Code: ags

Character.Animate(param - 1, .............);

If that's some kind of standard for your game and used a lot, then it would probably make sense to put this in an extender function:
Code: ags

function AnimateLoop(this Character*, int param)
{
   this.Animate(param - 1, ...............);
}

Then call it simply like
Code: ags

   cEgo.AnimateLoop(param);

You can use more parameters, of course.

Quote from: RenatoDias
Also, when walking, will the Loops above 8 be played automatically?
Not sure what you mean. Do you mean, will the character be animated with loops > 8 at the same time as he walks if you call Animate?.

Khris

The first 8 (4) loops of the normal view are used for walking animations, the rest is ignored unless you use them manually.

Do you mean can you add additional directions for really smooth movement? Not using the built-in walking mechanisms.

RenatoDias

Code: AGS
function AnimateLoop(this Character*, int param)
{
 this.Animate(param - 1, ...............);
}


From above, the this keyword after the open bracket line would be the loop #, for example, Loop9.Animate(param -1)?
Also, in this function, what is the param - 1 thing?
Can you clarify this for me, Crimsom Wizard?

Khris

That function is an extender function, extending the available methods for the Character object.
If you have a character called "cSomeGuy", you can now use cSomeGuy.AnimateLoop(5);

The word "this" inside the function will now point to the character "cSomeGuy", in other words the actual function call will be:

  cSomeGuy.Animate(4, ...);

(Since the parameter I used in the example is 5, param will have a value of 5, thus param - 1 equals 4.)

RenatoDias

So, param is the loop number?

I would do it like below?

Code: AGS
if (variable1==1){
cEgo.Animate(8);
}
else if (variable1==2{
cEgo.Animate(9);
}

Please correct this if wrong. 

Crimson Wizard

#7
RenatoDias, I was trying to explain, but maybe not well enough.

If you will do this:
Code: AGS
if (variable1==1){
cEgo.Animate(8);
}
else if (variable1==2{
cEgo.Animate(9);
}

You will have to add block of "else if" for every possible variable value. And what if you have like 100 possible options?

What I suggest you to do is to think of formula. How do you get Loop from variable? In the example you wrote above you use Loop number which is equal to variable1 + 7: when variable is 1, Loop is 8, when variable is 2, Loop is 9 (do you see the trend here?)

In other words, instead of writing dozens of if/else if, you may write simply:
Code: ags

cEgo.Animate(variable1 + 7);



Quote from: RenatoDias on Wed 28/11/2012 14:10:58
Code: AGS
function AnimateLoop(this Character*, int param)
{
 this.Animate(param - 1, ...............);
}

From above, the this keyword after the open bracket line would be the loop #, for example, Loop9.Animate(param -1)?
No, not at all. What I wrote should be understood literally. "This" is "this". "Param" is "param".
That's a function, that takes a Character and an integer value as parameters.

A topic about functions: http://www.adventuregamestudio.co.uk/wiki/?title=Scripting_tutorial_part_1#Functions_Explained
A topic about user-defined functions: http://www.adventuregamestudio.co.uk/wiki/?title=Scripting_tutorial_part_2#Your_own_functions
A topic about extender functions (that explains "this" word): http://www.adventuregamestudio.co.uk/wiki/?title=Extender_functions

RenatoDias

So, let's say I've already done the scripting for that, will it execute automatically? or I have to call the event from the script, if yes, how?

PS: Sorry for asking a seemingly unrelated question, but, I would like to use this topic instead of creating another one just for the question above.

Crimson Wizard

#9
Quote from: RenatoDias on Wed 28/11/2012 16:32:21
So, let's say I've already done the scripting for that, will it execute automatically? or I have to call the event from the script, if yes, how?
I think I am starting to realize what you are asking about...

Do you mean you want to make some OTHER loops (not 0-7) play automatically when character WALKS like if they were his walking animations?

Khris

Yeah, please tell us what you want to do as a designer would put it who hasn't a clue about AGS script.

Do you want to change the walking loops? As in, the character changes clothing or swims through a river, then continues walking on the other side?

RenatoDias

QuoteDo you mean you want to make some OTHER loops (not 0-7) play automatically when character WALKS like if they were his walking animations?
Not exactly. I want to know if the script is executed automatically by the game engine itself or I have to call the script using a object-oriented command, like we did back in AGS 2.7 for dialogs(which I never fully mastered)

Also, about my first post, here is what I want to do with all this scripting and variables:
Quote-Use those loops for other activities, such as only when the character is idle(thinking), fixing some broken object, using house appliances and such.
Refer to The Sims game's Fixing Broken Appliance scene. That would be hilarious in AGS.

Crimson Wizard

Quote from: RenatoDias on Wed 28/11/2012 17:27:05
Not exactly. I want to know if the script is executed automatically by the game engine itself or I have to call the script using a object-oriented command, like we did back in AGS 2.7 for dialogs(which I never fully mastered)
Oh, sorry, I understand now.
If you mean animation in particular, only Walking, Speaking and Idle animations are activated automatically, if you setup corresponding  properties for the character. Other kinds of animations should be run from script by calling command.

Quote-Use those loops for other activities, such as only when the character is idle(thinking), fixing some broken object, using house appliances and such.
Except for idle animation, which could be pre-set, you should call commands from script on your own at corresponding times.
There are techniques that let you make this easier for yourself, such as writing your own functions for each type of activity and calling them, so that you won't need to remember loop numbers and other related params all the time (see links I gave above).

RenatoDias

Quote from: Crimson Wizard on Wed 28/11/2012 17:47:50
Quote from: RenatoDias on Wed 28/11/2012 17:27:05
Not exactly. I want to know if the script is executed automatically by the game engine itself or I have to call the script using a object-oriented command, like we did back in AGS 2.7 for dialogs(which I never fully mastered)
Oh, sorry, I understand now.
If you mean animation in particular, only Walking, Speaking and Idle animations are activated automatically, if you setup corresponding  properties for the character. Other kinds of animations should be run from script by calling command.

Quote-Use those loops for other activities, such as only when the character is idle(thinking), fixing some broken object, using house appliances and such.
Except for idle animation, which could be pre-set, you should call commands from script on your own at corresponding times.
There are techniques that let you make this easier for yourself, such as writing your own functions for each type of activity and calling them, so that you won't need to remember loop numbers and other related params all the time (see links I gave above).
Then, how do I call the same code multiple times?
Can I use any of the functions below?
- DO{this}-WHILE(variable==1)?
or
- For(variable==1){this}
Thanks...
PS:The this is an example of function.

Crimson Wizard

Quote from: RenatoDias on Wed 28/11/2012 18:14:33
Then, how do I call the same code multiple times?
Can I use any of the functions below?
- DO{this}-WHILE(variable==1)?
or
- For(variable==1){this}
Thanks...
PS:The this is an example of function.

This is done with loops, similar like you wrote. AGS does not support "FOR" type of loop, only "WHILE".
But, seriously, this, as well as many other basic and advanced things, are covered in the manual.
Here's something about the loops:
http://www.adventuregamestudio.co.uk/wiki/?title=Scripting_tutorial_part_2#Loops
http://www.adventuregamestudio.co.uk/wiki/?title=Script_language_keywords#while

RenatoDias

I understand, now I ask:
Let's say I have the following function:
Code: AGS

function fix_computer(int compfixed){
compfixed=0;
    while (compfixed==0) do{
        cEgo.Animate(8);
        }
}

On this code, Loop 8 is being used for the fixing objects(appliances) animation.
Now, how would I call this function mid-game? A "Use Inventory Item(screwdriver) on Object(computer)" can call the function? If so, I would just put fix_computer() inside the brackets on the event for that to work?
-After called, will it keep repeating if a variable keeps the same value?
PS: Sorry for the "DO" keyword, I'm used to programming in C/C++.

Crimson Wizard

#16
Quote from: RenatoDias on Wed 28/11/2012 20:07:16
Now, how would I call this function mid-game? A "Use Inventory Item(screwdriver) on Object(computer)" can call the function? If so, I would just put fix_computer() inside the brackets on the event for that to work?
Basically, yes.
You should also check for what inventory item was used on computer like this:
Code: ags

if (player.ActiveInventory == iScrewdriver)
{
   // run actions here
}


Quote from: RenatoDias on Wed 28/11/2012 20:07:16
-After called, will it keep repeating if a variable keeps the same value?
No, it does not work like that. AGS scripts are single-threaded, and everything is executed consecutively. The code you wrote will loop forever.
There are two types of commands in AGS, blocking and non-blocking. Blocking commands make everything else wait until their execution is finished. Non-blocking commands will trigger some lengthy action and continue executing script.

Some functions may have a parameter that tells them if they should block the game or not. For example, making character animate for once while blocking the rest of the game is done like this:
Code: ags

cEgo.Animate(3, 1, 0, eBlock, eForwards);

Making character animate in a non-blocking way (letting game continue to run actions) is done like this:
Code: ags

cEgo.Animate(3, 1, 0, eNoBlock, eForwards);

Blocking is default.

If you want your character play animation once (like, using item on object), use Blocking animation. You do not need any while loops for that.
Simply:
Code: ags

function fix_computer()
{
   cEgo.Animate(8);
}

Khris

It sounds like you want a character to keep animating using a certain loop, while the game continues, right?
Let's solve this straight, without delving into extender functions and whatnot.

Code: ags
function oComputer_Useinv() {
  
  if (player.ActiveInventory == iScrewdriver) {
    player.Walk(140, 120, eBlock);
    player.LockView(player.NormalView);
    player.Animate(8, 4, eRepeat, eNoBlock);
  }
}


Of course this means that as soon as this interaction was called, when the player interacts with something else, the view has to be unlocked. There are a couple of ways to tackle this, but I still don't have the faintest idea of what you're trying to achieve here.

Quote from: RenatoDias on Wed 28/11/2012 20:07:16I'm used to programming in C/C++.
So why would you get completely stumped by "this" and function parameters...?
There's no shame in admitting that you don't know how to program as long as you read the manual and put some effort into solving your problems on your own before posting here.

RenatoDias

#18
Quote from: RenatoDias on Wed 28/11/2012 20:07:16I'm used to programming in C/C++.
So why would you get completely stumped by "this" and function parameters...?
There's no shame in admitting that you don't know how to program as long as you read the manual and put some effort into solving your problems on your own before posting here.
[/quote]

I know the basics of C/C++, such as loops and normal functions(if, switch...), but never went THAT deep to use function parameters like that. I know how to do a DO-WHILE loop, IF, ELSE, SWITCH and began to learn about functions. Haven't used function parameters and the "this" keyword yet, that's why I was so stumped. Also, I thought AGS had it's own little language, like GML(Game Maker).

Quote from: Khris on Wed 28/11/2012 21:25:54
It sounds like you want a character to keep animating using a certain loop, while the game continues, right?
Let's solve this straight, without delving into extender functions and whatnot.

Code: ags
function oComputer_Useinv() {
  
  if (player.ActiveInventory == iScrewdriver) {
    player.Walk(140, 120, eBlock);
    player.LockView(player.NormalView);
    player.Animate(8, 4, eRepeat, eNoBlock);
  }
}


Of course this means that as soon as this interaction was called, when the player interacts with something else, the view has to be unlocked. There are a couple of ways to tackle this, but I still don't have the faintest idea of what you're trying to achieve here.

Okay, let's a litte deeper. The text below is a bit "different", so be careful:
In my game, there will be scene like the following(read the bold line to know what I really want):
You arrive in a certain room of a ship you are in since the beggining of the game. The room is a prison, when you walk around, you see a girl, she has both her arms and legs tied, and a piece of tape on her mouth. She will be struggling, that is, "shaking" her body, trying to free herself. If you point the cursor on her, the cursor will change to a scissor, which enables the untie action. From then on(once you untie her), the girl will have her normal movement and follow you around.[...]
That "shaking" animation is what I want to loop.

Khris

Strictly speaking, AGS does have its own language. It's based on C++ and Java though.

For what you want, all you need to do is put this in the room's before fadein:

Code: ags
  cGirl.LockView(VIEW_NUMBER);
  cGirl.Animate(8, DELAY, eRepeat, eNoBlock);


In the untie interaction, call
Code: ags
  cGirl.UnlockView();

which will revert her frame handling to automatic standing/walking.

SMF spam blocked by CleanTalk