Any click on object (not working)? solved

Started by cinos, Fri 13/10/2006 13:45:59

Previous topic - Next topic

cinos

An object moves across the screen with eBlock to a location. It then animates with eNoBlock. When I click on the object nothing happens when it should add an inventory item then disappear. I have tried the codes below but they do otherthings to the heartstone. I thought this would be simple!!
//I have put this in the global script.
function repeatedly_execute_always ( )
{
Ã, 
Ã,  if (IsTimerExpired(1)==1)
Ã,  Ã,  Ã, oHeartstone1.Visible=false;
}

//Room script
if((answer.AsInt == Product)&&(Thrown==1))
{
Ã,  object[Thrown].Visible = false;
Ã,  GiveScore(5);
Ã,  PlaySound(3);
Ã,  object[0].Animate(1,6,eOnce,eNoBlock);
//The skeleton (object[0]) burns and the HEARTSTONE1 appears and moves
//across the screen. I want the player to click it before it disappears to place in the inventory.
Ã,  oHeartstone1.Visible=true;
Ã,  oHeartstone1.SetView(5);
Ã,  oHeartstone1.Animate(0, 1, eRepeat, eNoBlock, eForwards);
Ã,  oHeartstone1.Move(150, 200, 1, eBlock, eAnywhere);

//The oHeartstone1 stops here and allows the player to click it and an inventory item is added and the oheartstone1 disappears.NOT HAPPENING!! I think the script runs too fast.

Ã,  oHeartstone1.Animate(0, 1,eOnce, eNoBlock, eForwards);
Ã,  oHeartstone1.Animate(0, 1,eOnce, eNoBlock, eBackwards);
Ã,  oHeartstone1.Animate(0, 1,eOnce, eNoBlock, eForwards);
Ã,  SetTimer(1, 100);//if the player has not clicked the oHeartstone1 it will disappear when the timer runs out.
Ã,  //Maybe the script is running too fast to register the click?
Ã,  object[0].Visible=false;
Ã,  object[0].SetPosition(337, 269);
Ã,  PlaySound(1);
Ã,  PlaySound(4);
Ã,  object[0].Visible = true;
Ã,  object[0].SetView(3);
Ã,  object[0].Animate(2,6,eOnce,eBlock);
Ã,  object[0].Animate(0,6,eOnce,eNoBlock);
Ã,  object[0].Move(280,266,1,eNoBlock,eWalkableAreas);
Ã,  }
sectionstart object12_bÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function object12_b() {
Ã,  // script for Object 12 (HEARTSTONE1): Any click on object
player.AddInventory(iheartstone1);Ã, 
}
#sectionend object12_bÃ,  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart object12_cÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function object12_c() {
Ã,  // script for Object 12 (HEARTSTONE1): Any click on object
oHeartstone1.Visible=false;Ã, 
}

SSH

#1
Quote from: cinos on Fri 13/10/2006 13:45:59
Can anyone tell me the problem with this code?
No newlines!?  ;)

I think you want:
Code: ags

function repeatedly_execute_always () {
  if (mouse.IsButtonDown(eMouseLeft) && oHeartstone1.Animating) {
    player.AddInventory(iheartstone1); 
    oHeartstone1.Visible=false;
  }
}


You had too many closing brackets on the if line. And most of the brackets you had were redundant anyway. CTRL-B in the editor shows you how they match.


EDIT: I was only faster than dkh because I accidentally hit post before I had finished...

EDIT 2:
Actually, I'd be surprised if this does what you want... you want the player to pick up the heartstone WHENEVER THEY CLICK FOR THE WHOLE GAME? What if it is already picked up? What if the cursor is somewhere else? What if they are in a different room?

EDIT 3: Well, if the oHeartstone1 is going to work, the code has to be in the room script anyway, I guess...
12

DoorKnobHandle

1. It isn't "Repeatedly_Execute_Always", it's "repeatedly_execute_always".

2. You forgot the brackets after the funtion name: "repeatedly_execute_always ( )".

3. There is no need to put single conditions in brackets after the if-statement.

4. "if ( something == 1 )" can be replaced by "if ( something )".

5. You should format your code better using line-breaks.

This is how your code should look like:

Code: ags

function repeatedly_execute_always ( )
{
	if ( mouse.IsButtonDown ( eMouseLeft ) && oHeartstone1.Animating )
	{
		player.AddInventory ( iheartstone1 );
		oHeartstone1.Visible = false;
	}
}


EDIT: SSH was faster...

cinos

#3
I am new to coding. Thank you for your assistance dkh & ssh. If you look at my other post you will see that the heart stone1 only appears when a certain sequence of events happens. Sorry about how I write the scripts and I am taking your advice about the set out. I have removed the wait lines from the script but I still am unable to put the heart stone in the inventory. Is there such a command as If cursor over object?

Khris

There's Object.GetAtScreenXY(x, y) which in your case would be used like this:
Code: ags
Ã,  if (Object.GetAtScreenXY(mouse.x, mouse.y)==oHeartstone1) {
Ã,  Ã,  ...
Ã,  }


Btw, if this code doesn't HAVE to be inside rep_ex_always, you can put in a RunScript-action in the any click on object-Interaction of the Heartstone.

And you can't access objects by their script-o names in the global script, but it is possible to access them using the object[]-array. You might want to check the current room, too, so if this went into the global script, it would look like this:

Code: ags
function repeatedly_execute_always ( ) {
Ã,  if (player.Room==3 &&Ã,  mouse.IsButtonDown ( eMouseLeft )) {Ã,  Ã, // adjust room number & object number
Ã,  Ã,  if (object[1].Animating && Object.GetAtScreenXY(mouse.x, mouse.y==object[1] ) {
Ã,  Ã,  Ã,  player.AddInventory ( iheartstone1 );
Ã,  Ã,  Ã,  object[1].Visible = false;
Ã,  Ã,  }
Ã,  }
}

cinos

Thanks Khris I will try this out. I have modified the post above with the code I am trying to get to work. The problem is allowing time for the player to click on the heartstone. By the way is it possible for the player to actually click on the heart stone as it moves like a target?

SMF spam blocked by CleanTalk