Object coordinates

Started by sloppy, Tue 06/12/2005 20:59:48

Previous topic - Next topic

sloppy

I'm trying to make a slider puzzle.  I've made a room that is just a big square with smaller squares as objects (40x40).  I want it so that if you click one of the squares, it will move one square in a direction.  The way I figure it, you would need to get the object's coordinates +/- 40.
I'm not sure how.  I've tried Object[0].Move(object[0].X+40), (object[0].Y+0);
just to start off, but of course it doesn't work.

Can anyone help?

strazer

Try
  object[0].Move(object[0].X+40, object[0].Y+0); // note the lowercase o and the removed braces
or
  object[0].Move(object[0].X+40, object[0].Y+0, eBlock);

DoorKnobHandle

You need to pay attention to capitalization.
In this case "Object" and "object" is a great difference.

This line should work:
Code: ags

object[0].Move ( object[0].X + x_offset, object[0].Y + y_offset, 3 );


It will move the object 0 to a new position (replace x_offset and y_offset with your values for the new position) and it will use a speed of 3.

You were thinking the right way, though!

EDIT: strazer was faster.

Ashen

#3
You where both faster, but anyway:

Object.Move(int x, int y, int speed, optional BlockingStyle, optional WalkWhere);

So, you're missing a needed parameter for speed, at the very least. Also, without the WalkWhere parameter set to eAnywhere, the object needs a walkable area to move on - is there one? Try:

object[0].Move(object[0].X+40, object[0].Y, 3, eBlock, eAnywhere);

EDIT: Missing parameter? What missing parameter? ::)
I can't believe it took 3 of us to get this right ...
Also, culled some posts.
I know what you're thinking ... Don't think that.

sloppy

Yes that works.  Capitalization...such a stupid error.  And I think it's better to put a walkable area on so that it prevents the tiles from going off the big square.

How would I prevent a tile object from moving in a direction if another tile object is in its way? 

I've been working on this scripting for hours, and I think I'm in over my head.  Has anyone else tried to have one of these puzzles in their game?  I couldn't find one post about it.

DoorKnobHandle

That's a way more compicated question. You'd either need to code your own collision control (you store the x and y position of every tile and then before you move, you check if another tile is in the way) or you could change to using characters instead of objects, I guess.

Creating your own collision control is going to be hard if you never done that and if you don't have a little maths knowledge.

Ashen

#6
But, since each tile is an object, you could use Object.GetAtScreenXY() to check, something like:

if (Object.GetAtScreenXY(object[0].X+40, object[0].Y) == null) object[0].Move(object[0].X+40, object[0].Y, 3, eBlock);

Might take a little tinkering, though.
EDIT: And assumes you always move the objects by a set amount. It becomes a little more complicated (as dkh said) if you have total freedom of movement.  Without knowing exactly what you're after, it's hard to say.
I know what you're thinking ... Don't think that.

sloppy

Thanks Ashen, but I can't get the Object.GetAtScreen scripting to work.  And I've tried everything (as far as my understanding of it goes).

I was trying to make a tile game where there's only one space missing and you slide tiles back in order in a big square.  So tiles would only slide up and down and only the tile dimensions at a time.  It seemed like such a simple idea, but it's just beyond my abilities.

I think I'll quit while I'm behind and admit defeat. :'(

Ashen

#8
Figured that was what you were after - something like this, perhaps?
Ignore the 2 objects not in the slider bit (cup and '9' block).

Uses graphics by Scorpiorus, from a while back.

Check the code, see if it's any use to you. (There's some old, 2.62 style code int he global script, just ignore that, too. It's the room script stuff you want.)
I know what you're thinking ... Don't think that.

sloppy

#9
Oh, that's perfect.Ã,  I really appreciate this!

I've been working with the scripting, customizing it to what I want it to look like. 

Just one more question about this - How would you incorporate a sound effect when the person is successful in putting the tiles in the proper order?

Ashen

For that, you'd need to check the coords of each piece and compare them to the right coords for that piece, and trigger something if they were all in the right place.

Or ... The demo I uploaded is based on Scorpiorus' drag puzzle demo, so it has hotspots in place to check when the pieces are located right - you could use that too, something like:
Code: ags

function CheckSolved() {
  int correct;
  int i=1;
  while (i <= 8) { // or number of slide-pieces
    Hotspot *hot = Hotspot.GetAtScreenXY(object[i].X+20, object[i].Y-20); // Middle of tile
    if (hot.ID == i) correct ++;
    else correct = 0;
    i ++;
  }
  if (correct == 8) { // or number of slide-pieces 
    Display ("Yay, you!");
    PlaySound(1);
    // Anything else you want to happen...
  }
}

Might be a neater way, this is just the first that came to mind.

Run that after the movement code (in rep_ex at the moment) and it should automatically trigger the Display/PlaySound commands when the peices hit the right spot.
I know what you're thinking ... Don't think that.

Maverick

#11
I'm dealing with the same issue although the way I interpreted your problem was that you wanted something different than what the actual outcome is.
Ashen, is it possible to combine these threads? http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23854


Ashen

Maverick, check back in your thread, I think I see what the problem is. Alternatively, the code above will almost certainly work for you, with a little tweaking (since, as I said, it's based on Scorpiorus' as well).

It's possible to combine them, yes, but I don't think I will. Although they're about the same thing now, they weren't to start with - similar, yes, but diferent enough that combining them would confuse anyone trying to search for either problem (free-movement dragging, or fixed-movement sliding).
I know what you're thinking ... Don't think that.

sloppy

#13
Am I missing something?Ã,  When I put this in and test it:

function CheckSolved() {
Ã,  int correct;
Ã,  int i=1;
Ã,  while (i <= 8) { // or number of slide-pieces
Ã,  Ã,  Hotspot *hot = Hotspot.GetAtScreenXY(object.X+20, object.Y-20); // Middle of tile
Ã,  Ã,  if (hot.ID == i) correct ++;
Ã,  Ã,  else correct = 0;
Ã,  Ã,  i ++;
Ã,  }
Ã,  if (correct == 8) { // or number of slide-pieces
Ã,  Ã,  Display ("Yay, you!");
Ã,  Ã,  PlaySound(1);
Ã,  Ã,  // Anything else you want to happen...
Ã,  }
}

It says that nested functions not supported.Ã,  (Closing brace, etc.)
But it looks okay to me.Ã,  Is there a missing brace?

strazer

Probably a brace before or after this function. Try the "Match braces" function of the script editor.
Btw, you can use the [ code ] tag to avoid the smileys when posting code.

Ashen

There's no missing brace there - where have you put it in the room script?

When I said "call this after the movement code" I meant "paste this into the top of the room script, and add CheckCorrect(); after the movement script" - pasting the function declaration into rep_ex would generate a nested functions error.

If it's not that, check the script either side of wherever you pasted it (as strazer said,      while I was posting) - you might've accidentally deleted a brace in the process.
I know what you're thinking ... Don't think that.

sloppy

#16
Thanks for explaining it.Ã,  I understand it now and it works great.Ã, 


Now on a new line of questioning.  When the puzzle is completed, the display will come up.  But then you have to click again to get the sound effect.  Is there a way that these two things can occur simultaneously?

Ashen

Just reverse the lines.
Display() is blocking (makes the script wait until it's cleared before running the next line), PlaySound() isn't, so running it first will make the sound play over the message.
I know what you're thinking ... Don't think that.

sloppy

I hate it when the answer is so obvious.

sloppy

#19
Okay, here's one more small thing I can't figure out with this.Ã,  When this tile puzzle is finished, I wanted 3 things to signal that: A display message, sound effect, and the last tile to appear.Ã,  Everything works except the tile becoming visible.
Here's what I have:
if (correct == 8) {
Ã,  object[9].Visible = true;
Ã,  Ã,  PlaySound(3);
Display ("You solved the puzzle!");
}

But the object won't become visible.
So why wouldn't object 9 appear along with the display and the sound?

SMF spam blocked by CleanTalk