Charater.Animate problem

Started by CatLover, Sun 11/04/2010 01:48:10

Previous topic - Next topic

CatLover

I am trying to make an npc animate constantly, using Character.Animate in the room script, but its not working.

First, I tried this:
function cMiner.Animate(5, 5, eRepeat, eNoBlock);
but it said "Variable cMiner already imported"

Next I tried it without "function":
cMiner.Animate(5, 5, eRepeat, eNoBlock);
but that created a parse error "Unexpected cMiner"

What should I do? ??? 

P.S. I am new to AGS and this is my first post, so I've probably done soething really stupid.

Ryan Timothy B

#1
It's supposed to be run within a function, not as a function or outside of a function.

If this Miner was to animate from the moment you enter that background, you add it to the After Fade In function, like so:
Code: ags
function room_AfterFadeIn()
{
   cMiner.Animate(5, 5, eRepeat, eNoBlock);
}

Note: this must be created from within the room editor, or else it won't work -- Unless you've already done so.

How to create the After Fade In function:
In the room editor, on the bottom of the project tree, click on the lighting bolt and you'll see "Enters Room after fade-in".  Click on the dots beside it and it will be created in the room script (exactly like above without the character.animate).



If you were to actually create a function and call it at a certain point, you do this (outside all other functions):
Code: ags

function AnimateMiner()
{
  cMiner.Animate(5, 5, eRepeat, eNoBlock); 
}

You really wouldn't want to create a function for a single action such as this.  I'm showing you since you didn't seem to know how a function worked.

Then when you need to use it within your scripts, you just simply call:
Code: ags

AnimateMiner();


But make sure this doesn't get thrown into the repeatedly execute script without some kind of boolean check to prevent it from being called over and over.
Also functions must be placed above where they will be called.

CatLover

Quote from: Ryan Timothy on Sun 11/04/2010 03:04:12
It's supposed to be run within a function, not as a function or outside of a function.

If this Miner was to animate from the moment you enter that background, you add it to the After Fade In function, like so:
Code: ags
function room_AfterFadeIn()
{
   cMiner.Animate(5, 5, eRepeat, eNoBlock);
}

Note: this must be created from within the room editor, or else it won't work -- Unless you've already done so.

How to create the After Fade In function:
In the room editor, on the bottom of the project tree, click on the lighting bolt and you'll see "Enters Room after fade-in".  Click on the dots beside it and it will be created in the room script (exactly like above without the character.animate).



If you were to actually create a function and call it at a certain point, you do this (outside all other functions):
Code: ags

function AnimateMiner()
{
  cMiner.Animate(5, 5, eRepeat, eNoBlock); 
}

You really wouldn't want to create a function for a single action such as this.  I'm showing you since you didn't seem to know how a function worked.

Then when you need to use it within your scripts, you just simply call:
Code: ags

AnimateMiner();


But make sure this doesn't get thrown into the repeatedly execute script without some kind of boolean check to prevent it from being called over and over.

Thanks a lot Ryan Timothy!!!

SMF spam blocked by CleanTalk