Why is this extra animation happing?

Started by bx83, Sun 11/06/2017 04:32:31

Previous topic - Next topic

bx83

Please see video: http://redrom.ltd/img/ice_video_20170611-130152.webm

Why is the second part happing, when the main character picks the croissant off the floor?
It's supposed to:
-walk down the screen to a predefine point
-oustretch arm
-croissant is gone

What actually happens
-slides down screen, repeatedly going the outstrething arm animation
-stops, does the animation again
-croissant is gone

I've tried two different walkable areas -- straight down the side, and jagged -- but it still happens.
Here's the code:

Code: ags

function oFishBowl_Interact()
{
	cJulius.Walk(472, 476, eBlock, eWalkableAreas);
	cJulius.Phylactere("How am I making room for all these objects?");
	cJulius.Animate(8, 0, eOnce, eBlock);			//high pickup left
	cJulius.AddInventory(iFishEye, 0);
	oFishBowl.Visible=false;
}

function oFishBowl_Look()
{
  cJulius.Phylactere("A lens which is home to a fish.");
}


function oCroissant_Interact()
{
	cJulius.Walk(315, 719, eBlock, eWalkableAreas);
	cJulius.Animate(8, 0, eOnce, eBlock);			//high pickup left
	cJulius.AddInventory(iCroissant, 0);
	oCroissant.Visible=false;
}

function oCroissant_Look()
{
	cJulius.Phylactere("Delicious.");
}


Both the first (fishbowl) and second part (croissant) are the same; but they have two different results.

It happens sometimes in other situations, but ALL the time in the one shown in this video.

I've moved the location of the main character, but it stil happens.

Cassiebsg

That sounds like you forgot to unlock the view at one point, since he's performing the pickup animating while walking, so my guess if that just prior to that you locked his view to do an animation of raising his arm and you never unlocked it...

You're suppose to lock your view before you animate it, and then release it once you are finshed (I suggest you do a function for it if you don't wish to type 3 lines of coed every time he picks up something)... anyway here's the lines you are missing on the code...
Code: ags

cJulius.LockView(vPickup); // you can use either the view name or number
cJulius.Animate(8, 0, eOnce, eBlock);
cJulius.UnlockView();

There are those who believe that life here began out there...

Khris

Loop 8 sounds like the pickup animation is part of your NormalView, don't do that; use an extra view for the pickups. This also forces you to switch views for the animation. I also recommend writing a custom Character.PickUp() function that receives eLow / eMiddle / eHigh as parameter. You can even pass along the inventory item and object:

Code: ags
// header
enum PickUpHeight {
  eLow, eMiddle, eHigh
};

import function PickUp(this Character*, PickUpHeight puh, InventoryItem *i, Object *o);

// main script
function PickUp(this Character*, PickUpHeight puh, InventoryItem *i, Object *o) {
  int dir = this.Loop; // get direction character is facing
  // puh: eLow = 0, eMiddle = 1, eHigh = 2
  int loop = ?; // use dir & puh to calculate pickup view loop
  this.LockView(PICKUP);
  this.Animate(loop, 0, eOnce, eBlock);
  this.AddInventory(i);
  o.Visible = false;
  this.UnlockView();
}


Now you can call cJulius.PickUp(eLow, iCroissant, oCroissant); and everything will be taken care of automatically.

bx83

Thankyou :)

Only one problem (and I'm sure this is a boneheaded mistake, but nothing makes it go away), the function I created in GlobalScript will not work in the room.

in GlobalScript script:

Code: ags

function PickUp (this Character*, int height, InventoryItem *i, Object *o)
{
  // height: eLow = 0, eHigh = 1
	int loop=0;

	if (height==0) {
		height=50; //low
	} else {
		height=49;	//high
	}

	if (this.x >= o.X) {
		loop=2;	//right
	} else {
		loop=1;	//left
	}
	
  this.LockView(height);
  this.Animate(loop, 0, eOnce, eBlock);
  this.AddInventory(i);
  o.Visible = false;
  this.UnlockView();
}


function PiratesLeaveToBar ()
{
...


in GlobalmScript header:

Code: ags

...
import function PiratesLeaveToBar ();
import function PickUp (this Character*, int height, InventoryItem *i, Object *o);


All compiles; nothing works in 'room16':
Code: ags

        ...
	cJulius.Phylactere("How am I making room for all these objects?");
	pickUp(cJulius, 1, iFishEye, oFishBowl);
}

Undefined Token: 'pickUp'

I've tried:
-recompiling with a different name
-changeing the order in which the function comes in the GlobalScript script
-bashing my head against a brick wall

All compile, no errors; until I use it in a room script.

I've done this with about 20 other custom functions; they import into the game fine, I use them in rooms, nothing happens.

What should I do? I know it's something obvious :/

Snarky

Check your capitalization: PickUp/pickUp.

bx83

#5
Not this. I've tried changing it (function and header) to PickUp, pickUp, pickUpObject etc. Don't know how the above happened :p.. but still when I write the function name nothing comes up once compiled, not even if I reset the editor, open and close rooms...

Also no errors when I change function order, as with other functions which generate a "defined twice" error.

Snarky

#6
Well, you do need to keep it consistent (unlike the code you posted), but reading your code more closely, you're also calling it incorrectly. When you have a function with a "this" argument, you need to call it on that type. So instead of pickUp(cJulius, 1, iFishEye, oFishBowl); it should be cJulius.PickUp(1,iFishEye, oFishBowl); as in Khris's example.

Also, Khris showed you how to do an enum for Low/Middle/High. Why aren't you doing that instead of using a number? It is much better to use an enum, as it makes the code so much more readable and ensures that you don't pass an incorrect value by accident.

bx83

Ah, that's it :))
I'm not using an enumeration as there's no "mid" view, only high and low animations. But I might as well try (first time I've defined a struct).
I need to read Kris's examples more closely.

Snarky

Cool, sorry if I was short with you.

If you have a variable that can only take one of two values, it's best to either use a bool (e.g. in this case "isHigh"), or (particularly if there's any chance at all that it might be extended in the future, or if the values can't be "compared" in some way) an enumeration.

Crimson Wizard

#9
Quote from: Snarky on Sun 11/06/2017 14:53:36
If you have a variable that can only take one of two values, it's best to either use a bool (e.g. in this case "isHigh")

BTW, from my own experience I learnt that having enums with only 2 options instead of bool may be preferred in many cases, especially when there is a lot of arguments in function, because it will be easier to understand what the function is doing without checking for argument names in function declaration.

E.g. imagine a call like
Code: ags

MyFunc(true, true, false, true, false);

You and your teammates (if there are any) will break your heads trying to remember what those values mean :).
If instead it looks like (all names are made up) -
Code: ags

MyFunc(eBlock, eDefaultSpeed, eNotSkippable, eRepeat, eIgnoreCollisions);

you will at least be able to guess what is going on.

Khris

#10
Yes, it's an extender function, that's why it's this Character* and not Character *cha in the parameters list.
I'd also always use variable names that aren't confusing, like PICKUPVIEW for the view containing the pickup animations, as opposed to height.

And stick to the enum; always plan ahead for possible later changes.

SMF spam blocked by CleanTalk