Object coordinates

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

Previous topic - Next topic

Gilbert

Will it be possibe that the object was hidden under other stuff because of baseline, etc. settings.

sloppy

I thought that too, but I don't think that's it. 

I tested this in other ways, like putting another object in an area outside the main square and setting it to disappear when the puzzle is done.  Once again, nothing happens.

Gilbert

Are there any code which will hide the object in your script? Chances are you put that somewhere in your script which would be executed after it's set visible (like in the rep_ex function, say for example).

sloppy

yes, that must be it  This is the scripting in the Repeatedly Execute:

if (ob != null) {
      ob.Baseline = 0;
      if (Object.GetAtScreenXY(ob.X + 40, ob.Y-1) == null && GetWalkableAreaAt(ob.X+40, ob.Y-1) != 0) {
        ob.Move(ob.X+40, ob.Y, 3, eBlock);
        PlaySound(2);
      }
      else if (Object.GetAtScreenXY(ob.X - 40, ob.Y-1) == null  && GetWalkableAreaAt(ob.X-40, ob.Y-1) != 0) {
        ob.Move(ob.X-40, ob.Y, 3, eBlock);
        PlaySound(2);
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y-41) == null  && GetWalkableAreaAt(ob.X, ob.Y-41) != 0) {
        ob.Move(ob.X, ob.Y-40, 3, eBlock);
        PlaySound(2);
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y+39) == null  && GetWalkableAreaAt(ob.X, ob.Y+39) != 0) {
        ob.Move(ob.X, ob.Y+40, 3, eBlock);
        PlaySound(2);
      }
      ob = null;
    }
  }

I don't fully understand what it all means, I used and modified the scripting from Scorpiorus.  Is there a way around this?

Gilbert

There doesn't seem to be problem in the code, are you sure object[9] was placed at the correct coordinates?

Maverick

#25
Insert Wait statement

object[9].Visible=true;// Initially not visible in editor
Wait(5);

Should work if everything else is in place.
AGS needs time to think before blocking code (sound, display) unless you use free channels for sound PlaySoundEx(int sound, int channel)

Ashen

Code: ags

if (correct == 8) {
  object[9].Visible = true;
    PlaySound(3);
Display ("You solved the puzzle!");
}

Oddly, it works perfectly well for me exactly as you've got it - and assuming you haven't made any major changes, we should have the same code. Are you sure it's object 9 you want to switch on, and not object 0? (Sorry, obvious I know, but that's usually where I go wrong.)

Could you post the rest of the rep_ex code - there should be at least a little more before the bit you showed earlier, unless you've made major changes. (I don't really think the problem will be there, but it couldn't hurt to check.)
I know what you're thinking ... Don't think that.

sloppy

Well it works now that I put that Wait statement in.  Thanks Maverick.

That was quite frustrating that it wouldn't work any other way, especially if it works for you, Ashen.
But thanks guys for all your help.

sloppy

So here's a new question.  I have a "sliding" sound effect everytime you move a tile into position.  So that the sound happens at the same time of the tile object movement, I've made the object move nonblocking. 

Works fine except when the last tile goes into place at the solution.  Then the victory sound effect and display message occurs before the last tile goes into place.   Is there a way that the movements can be nonblocking but still wait for the tile to finish at the very end before the display message and sound effect comes up?

Maverick

You can add a Wait() statement just before the spot where you want the victory sound to play. It will take a bit of tweaking to find the correct value but it should work.

Gilbert

You don't need to work out the wait() value if you just want it to stop after animation, just do something like:

while (object[curobjnum].Moving) Wait(1);
PlaySoundblahblabla...

where curobjnum is the object # of the last moving tile.

sloppy

#31
Thanks Gilbot, that would be perfect except I don't know which object will be the last to go into place because there's 8 tiles.  Is there a way of stating while(object[1-8].Moving, or something to that effect?

EDIT: Forget it.  I repeated the while(object) command for all 8 objects and it works.  It seems like there would be a more efficient way of doing that, though.

Ashen

#32
You could set a variable before you set ob to null, then use that, i.e.:
Code: ags

if (ob != null) {
  // Blah blah
  //Movement code
        else if (Object.GetAtScreenXY(ob.X, ob.Y+39) == null  && GetWalkableAreaAt(ob.X, ob.Y+39) != 0) {
        ob.Move(ob.X, ob.Y+40, 3, eBlock);
        PlaySound(2);
      }
      curobjnum = ob.ID;
      ob = null;
    }


Then you should be able to use while (object[curobjnum].Moving) Wait(1); as Gilbot suggested.
(Alternatively, you might be able to call ob = null; inside/after CheckCorrect(), and just use ob.Moving.)
I know what you're thinking ... Don't think that.

sloppy

Going back to this.  I wanted to have a sound effect at the same time that the tiles moved.  To do that, I would make each tile move a nonblock, otherwise the sound effect would wait for the object move, and it would sound off.
Here's how I have it:

if (mouse.IsButtonDown(eMouseLeft)) {
    if (button_pressed==0) {
      button_pressed = 1;
     
      ob = Object.GetAtScreenXY(mouse.x, mouse.y);
    }
  }
  else {
    button_pressed=0;
    if (ob != null) {
      ob.Baseline = 0;
      if (Object.GetAtScreenXY(ob.X + 40, ob.Y-1) == null && GetWalkableAreaAt(ob.X+40, ob.Y-1) != 0) {
        ob.Move(ob.X+40, ob.Y, 3, eNoBlock);
                PlaySound(5);
      }
      else if (Object.GetAtScreenXY(ob.X - 40, ob.Y-1) == null  && GetWalkableAreaAt(ob.X-40, ob.Y-1) != 0) {
        ob.Move(ob.X-40, ob.Y, 3, eNoBlock);
                PlaySound(5);
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y-41) == null  && GetWalkableAreaAt(ob.X, ob.Y-41) != 0) {
        ob.Move(ob.X, ob.Y-40, 3, eNoBlock);
                PlaySound(5);
      }
      else if (Object.GetAtScreenXY(ob.X, ob.Y+39) == null  && GetWalkableAreaAt(ob.X, ob.Y+39) != 0) {
        ob.Move(ob.X, ob.Y+40, 3, eNoBlock);
                PlaySound(5);
      }
      ob = null;
    }
  }

But when I make the tile move eNoBlock, if the tiles are rapidly clicked on, they'll sometimes go too far and go off the track, so to speak. 

Can anyone think of a way to make the sound effect occur at the same time as the tile movement, but still make the tiles wait for each move before it goes into place?

Gilbert

Can't you just put the PlaySound() lines before the object moving lines (set to BLOCKING)?

sloppy

That's what a fresh pair of eyes will do.  That does work.  Thanks so much for the quick response.

SMF spam blocked by CleanTalk