Drop and Drag Script

Started by Ghostlady, Fri 31/07/2009 04:41:34

Previous topic - Next topic

Ghostlady

I am creating a drop and drag puzzle that is made up of very skinny strips of a picture that will fit into a grid with lines going up and down.  Think of a fan, but all sections upright.  When the object is over the a hotspot (be it right or wrong) I move the object to fit in the grid correctly.  Couple things going on that I don't understand.  I can play the puzzle while running with debug.  Sometimes it works and sometimes it doesn't.  When it doesn't, it seems to stop and none of the objects are clickable anymore.  If I run with the debugger off, I can only move one strip of picture and then the same thing happens.  None of the objects are clickable anymore.  The game is 640 x 480.  Can anyone see what I am doing wrong?

Here is my script:

// room script file
  int button_pressed;
  Object*ob;
 
function Checksolved() {
  int i = 1;
  int correct;
  while (i < Room.ObjectCount) {
    Hotspot *ho = Hotspot.GetAtScreenXY(object.X, object.Y);
    if (ho.ID == i) correct ++;
    else correct = 0;
    i ++; }

  if (correct == 15) {
    Display("Puzzle has just been solved!");
    Wait(40);
   
    object[1].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[1].RemoveTint();
   
    object[2].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[2].RemoveTint();
   
    object[3].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[3].RemoveTint();
   
    object[4].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[4].RemoveTint();
   
    object[5].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[5].RemoveTint();
   
    object[6].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[6].RemoveTint();
   
    object[7].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[7].RemoveTint();
   
    object[8].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[8].RemoveTint();
   
    object[9].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[9].RemoveTint();
   
    object[10].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[10].RemoveTint();
   
    object[11].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[11].RemoveTint();
   
    object[12].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[12].RemoveTint();
   
    object[13].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[13].RemoveTint();
   
    object[14].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[14].RemoveTint();
   
    object[15].Tint(0, 0, 100, 80, 0);
    Wait(10);
    object[15].RemoveTint();
   
    player.ChangeRoom(142);  }
}

function room_RepExec()

  if (GUI.GetAtScreenXY(mouse.x, mouse.y)!=null) {
      if(Mouse.Mode!=eModeUseinv) {
         mouse.UseModeGraphic(eModePointer);}}
  if (Mouse.Mode == eModeUseinv) {     
       Mouse.UseDefaultGraphic(); }
       
  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) {
      Hotspot *ho = Hotspot.GetAtScreenXY(ob.X, ob.Y);
      if (ho == hstick1) {
          object[ob.ID].Move(79, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick2) {
          object[ob.ID].Move(90, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick3) {
          object[ob.ID].Move(101, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }
         
      if (ho == hstick4) {
          object[ob.ID].Move(111, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick5) {
          object[ob.ID].Move(122, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick6) {
          object[ob.ID].Move(133, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }
         
      if (ho == hstick7) {
          object[ob.ID].Move(144, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick8) {
          object[ob.ID].Move(155, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick9) {
          object[ob.ID].Move(167, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }
         
      if (ho == hstick10) {
          object[ob.ID].Move(178, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick11) {
          object[ob.ID].Move(189, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick12) {
          object[ob.ID].Move(199, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }
         
      if (ho == hstick13) {
          object[ob.ID].Move(211, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick14) {
          object[ob.ID].Move(222, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }

      if (ho == hstick15) {
          object[ob.ID].Move(232, 215, 4, eBlock,  eAnywhere);
          Checksolved(); }
         
      if (ho != null && ho.ID == ob.ID) {
          player.Say("That's right."); }
         
//      Display("correct %d (correct=%d)", correct);   
      ob.Baseline = 0;
      ob=null;
    }
  }
   

  if (ob != null) {
    int width  = Game.SpriteWidth[ob.Graphic];
    int height = Game.SpriteHeight[ob.Graphic];
    ob.Baseline = game.room_height;
    ob.SetPosition(mouse.x-width/2, mouse.y+height/2);
  }
}
 
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

tzachs

I tried your script and it worked fine for me (with & without debug and I tried it at least 10 times). I did it on a smaller scale with 3 objects & hotspots, I only had to change the line
Code: ags

Hotspot *ho = Hotspot.GetAtScreenXY(object.X, object.Y);

which doesn't compile, to
Code: ags

Hotspot *ho = Hotspot.GetAtScreenXY(object[i].X, object[i].Y);

But I guess you just pasted it wrong, so my only lead is that maybe some other script is in the way or maybe there is a hostpot/object with a higher baseline that prevents other objects from being clicked...

Ghostlady

#2
Hotspot *ho = Hotspot.GetAtScreenXY(object.X, object.Y);  is not correct, must have picked up the wrong room script because I have two rooms with the same script so I can play without destroying the original. Do you think it can be happening when an object is clicked on top of another one?  Or that the hotspots are too close together or the objects are too close together?  Can you test it again and put one object on another multiple times?  I've attached a screenshot to show how close together the objects will be.

I noticed something else, if I slide the objects in from the left to the right, it now works.  I am thnking the 640 x 480 is messing with the hotspots.  Any suggestions?

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

tzachs

I tried it with objects on top of each other and it worked...
I have some thoughts:
1. Try it without the two lines that change the baseline and see if it helps.
2. If it doesn't, you can put a label in the room, and write in it the name of the hotspots&objects that the mouse is pointing at, then you will see which object may be hiding another object...

Ghostlady

The problem is with the "move" statements.  I commented them out and it works.  For some reason that is beyond me, though I think the 640 x 480 is coming into play, is that when I move the object so it is directly on the hotspot, all lined up perfect, for some reason the game isn't recognizing the placement on the hotspot.  It is displaced.  Even when I draw the hotspots, if I was only dealing with the bottom left hand corner, I have to draw it under the grid for it to be picked up.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

SMF spam blocked by CleanTalk