object move

Started by duanne_boy, Tue 25/09/2012 23:21:45

Previous topic - Next topic

duanne_boy

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);
}

Crimson Wizard

#1
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: ags

object[2].Visible = false;




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: ags

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

In that case the item will be picked up only after object ended moving.


Finally your script should look like:
Code: ags

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


//---------------------------
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: ags

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

duanne_boy

#2
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

Crimson Wizard

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);

duanne_boy

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

duanne_boy

#5
ok sorted it. i had another object over it that i made none visible which was blocking it

cheers all the same

Crimson Wizard

#6
Quote from: duanne_boy on Tue 25/09/2012 23:55:44
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.


Quote from: duanne_boy on Tue 25/09/2012 23:58:29
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

duanne_boy

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

Crimson Wizard

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...

duanne_boy

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

duanne_boy

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?

Crimson Wizard

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.

duanne_boy

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.

Crimson Wizard

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: ags

function room_RepExec()
{
  if (!oSCamera.Moving) // only start move if it is not moving at this moment
  {
    if (oSCamera.X == 482)
      oSCamera.Move(1507, 357, 5, eNoBlock, eAnywhere); // if it is in the left corner, move it right
    else
      oSCamera.Move(482, 357, 5, eNoBlock, eAnywhere); // else move it left
  }
}

duanne_boy

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.

Crimson Wizard

#15
Following like that is usually done simply by checking coordinates of a target.

Like
Code: ags

oSCamera.Move(player.x, 357, 5, eNoBlock, eAnywhere);

smartastreacle

Thank you Crimson Wizard - this really helped me too. Especially this - if (!oSCamera.Moving)
It solved all my problems.

SMF spam blocked by CleanTalk