Author Topic: object move  (Read 5379 times)

object move
« on: 25 Sep 2012, 23:21 »
hi im trying to get a object to move before pick up
but nothing happens. they it just stays where i place it.
i read the manual and found abit a code about object move
but im having no joy

heres the code im trying please help.

function oCoins_Interact()

object[2].Move(500,40,3);

cAllann.AddInventory(iCoins);
}

Re: object move
« Reply #1 on: 25 Sep 2012, 23:39 »
You are having two problems here simultaneously.

First problem is that you do not hide object after inventory item was given to player. You should understand that room object and inventory item are separate things and the fact that item is given to player does not mean object will dissapear on its own.
To make it dissapear add this command:
Code: Adventure Game Studio
  1. object[2].Visible = false;
  2.  



Second, this is very important to know: there are two types of actions in AGS: blocking and non-blocking.
Simply put, blocking action makes everything else wait until it is finished, while non-blocking makes other actions take place right away.

If you check description of the Move function in the manual, you will see there are extra optional parameters: BlockingStyle and WalkWhere. We are interested in BlockingStyle at this time. By default it is Non-blocking, which means that if you call Move like you did, the next commands will be executed right away, practically same time. This is why the item is being taken immediately without waiting for the movement.

What you probably should do is this:
Code: Adventure Game Studio
  1. object[2].Move(500, 40, 3, eBlock);
  2.  
In that case the item will be picked up only after object ended moving.


Finally your script should look like:
Code: Adventure Game Studio
  1. object[2].Move(500,40,3, eBlock);
  2. cAllann.AddInventory(iCoins);
  3. object[2].Visible = false;
  4.  

//---------------------------
EDIT: Also, I am not sure, but there's a chance something else is wrong here. I am a bit confused by your explanation, you said that object stays on same place, while it should have at least moved simultaneously with item being picked up.
If the solution above does not work, you should check three more things:
- if the object you are trying to move is really object #2?
- if target coordinates are actually different from object's initial position;
- try to add another parameter to Move function like this:
Code: Adventure Game Studio
  1. object[2].Move(500,40,3, eBlock, eAnywhere);
  2.  
« Last Edit: 25 Sep 2012, 23:49 by Crimson Wizard »

Re: object move
« Reply #2 on: 25 Sep 2012, 23:50 »
ok this is how ive got it

function oCoins_Interact()

object[2].Move(500,40,3, eBlock);
cAlien.AddInventory(iCoins);
object[2].Visible = false;


}

but nothing happens all i get is the watch timer.
trying to get the item to move to the player. remove it from screen. and add to inventory.
the object i have i imported as a inventory item

Cheers
« Last Edit: 25 Sep 2012, 23:53 by duanne_boy »

Re: object move
« Reply #3 on: 25 Sep 2012, 23:52 »
Please, check the following:

- Is the object you are trying to move is really object #2? Can it be you are using wrong object index?
- Are target coordinates are actually different from object's initial position?
- Try to add another parameter to Move function like this:
object[2].Move(500,40,3, eBlock, eAnywhere);

Re: object move
« Reply #4 on: 25 Sep 2012, 23:55 »
the object i inported as a inventory item.

the item is on the floor lower than than target cords.

i want it to like rise from the ground befor disaparing

Re: object move
« Reply #5 on: 25 Sep 2012, 23:58 »
ok sorted it. i had another object over it that i made none visible which was blocking it

cheers all the same
« Last Edit: 26 Sep 2012, 00:02 by duanne_boy »

Re: object move
« Reply #6 on: 26 Sep 2012, 00:06 »
the object i inported as a inventory item.
Wait, let's clear this out.
Inventory item cannot lie on the floor. Only Room Objects do. Inventory items can be only in character's inventory.
In other words, you have two types of things:
- Room Object - that is something you put in the room (on floor or anywhere else).
- Inventory item - is something characters can have in their inventory.

What people usually do, they put Room Object in the room and when character interact with that object they:
- Hide the Room Object.
- Add Inventory Item to character's inventory.

That is exactly what you are trying to do. I just wanted to clarify the terminology.


ok sorted it. i had another object over it that i made none visible which was blocking it
Ahhh... you made it Solid right?
So is it working now?
If you need that second object, I think you may turn Solid off when second object is not visible
« Last Edit: 26 Sep 2012, 00:08 by Crimson Wizard »

Re: object move
« Reply #7 on: 26 Sep 2012, 00:20 »
ok so yea i moved the object out the way the was hiding the coins and now they rise.
i want tocover them back up..

i know how to hide the object. but how do you make it nosolid

Re: object move
« Reply #8 on: 26 Sep 2012, 00:26 »
Actually I just checked the manual and it sais that Solid objects do not block other objects. Besides an object does not become Solid on its own, you have to make it Solid yourself.
So, to be honest, I do not know what was happening there...

Re: object move
« Reply #9 on: 26 Sep 2012, 00:28 »
thank you for your help.

it was that fact the object covering it was solid.

read the manual found the code and used this

oTableDoor.Visible = false;
  oTableDoor.Solid = false;

everything works like a dream

Re: object move
« Reply #10 on: 26 Sep 2012, 21:10 »
hi again, ive been playing around with this.
and now ive a new problem.

i want to keep something moving in a room. but i notice it stops the script from running.
and stops the play from doing anything.

tryed using the noeblock command and that did not work.

is this even possible?

Re: object move
« Reply #11 on: 26 Sep 2012, 21:33 »
Ofcourse that's possible.
Please post you code, so we could see what's wrong with it.
Also it would be nice to have more detailed explanation on what you are trying to do.

Re: object move
« Reply #12 on: 26 Sep 2012, 22:59 »
hi.
ive a security camera sprite that sit just below the ceiling at one end of my room.
and i want it to wait at one end of the room for so many seconds before move back so its going back and fourth across scanning the room .

here is the code i have for it

function room_RepExec()
{
oSCamera.Move(1507, 357, 5, eBlock, eAnywhere);
Wait(120);
oSCamera.Move(482, 357, 5, eBlock, eAnywhere);
}

it moves back and fourth like i want it to but i get the timer watch, and nothing else works.

Re: object move
« Reply #13 on: 26 Sep 2012, 23:23 »
First of all, it is eNoBlock for non-blocking actions.
Secondly, you misunderstand the logic behind room_RepExec.

Functions like RepExec are executed every game tick (40 times per second by default). Your camera here will try to move back and forth 40 times per second, which does not makes any sense ofcourse.
What you should do:
1. Check if the object is not moving, and make it start moving.
2. If the object is still moving, don't do anything.
This will repeat the check until object has stopped, and then launch it into opposite direction:
Code: Adventure Game Studio
  1. function room_RepExec()
  2. {
  3.   if (!oSCamera.Moving) // only start move if it is not moving at this moment
  4.   {
  5.     if (oSCamera.X == 482)
  6.       oSCamera.Move(1507, 357, 5, eNoBlock, eAnywhere); // if it is in the left corner, move it right
  7.     else
  8.       oSCamera.Move(482, 357, 5, eNoBlock, eAnywhere); // else move it left
  9.   }
  10. }
  11.  

Re: object move
« Reply #14 on: 26 Sep 2012, 23:35 »
ah i see now :)
 
thank you again that works fine.

just wandering where i would need to look in the manual.
if i wanted to have it follow the char insted of just moving like that.

Re: object move
« Reply #15 on: 26 Sep 2012, 23:47 »
Following like that is usually done simply by checking coordinates of a target.

Like
Code: Adventure Game Studio
  1. oSCamera.Move(player.x, 357, 5, eNoBlock, eAnywhere);
  2.  
« Last Edit: 26 Sep 2012, 23:50 by Crimson Wizard »

Re: object move
« Reply #16 on: 01 Oct 2021, 16:53 »
Thank you Crimson Wizard - this really helped me too. Especially this - if (!oSCamera.Moving)
It solved all my problems.