Slider Puzzle Help

Started by Ghostlady, Mon 02/01/2006 15:41:59

Previous topic - Next topic

Ghostlady

I found this post - HERE with scripting for a slider puzzle.Ã,  I download the slider.zip and it works great.Ã,  When I try the same code in my game the blocks will not move.Ã,  One of the differences is that my game is 640 x 480 as opposed to the 320 x 240.Ã,  Another is that my object blocks are 100 x 100 instead of 40 x 40.Ã,  Are the "X" and "Y" coordinates different when using 640 x 480?Ã,  Instead of checking "40" I was checking "100" and then I tried "50" because it look like it needed 50 when viewing the mouse position.Ã,  This is a first person game and the characters are transparent.Ã, 

Code from download:

Code: ags
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);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  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);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  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);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  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);


This is my code:

Code: ags
if (Object.GetAtScreenXY(ob.X + 50, ob.Y-1) == null && GetWalkableAreaAt(ob.X+50, ob.Y-1) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X+50, ob.Y, 3, eNoBlock, eAnywhere);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (Object.GetAtScreenXY(ob.X - 50, ob.Y-1) == nullÃ,  && GetWalkableAreaAt(ob.X-50, ob.Y-1) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X-50, ob.Y, 3, eNoBlock, eAnywhere);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (Object.GetAtScreenXY(ob.X, ob.Y-51) == nullÃ,  && GetWalkableAreaAt(ob.X, ob.Y-51) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X, ob.Y-50, 3, eNoBlock, eAnywhere);
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (Object.GetAtScreenXY(ob.X, ob.Y+49) == nullÃ,  && GetWalkableAreaAt(ob.X, ob.Y+49) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X, ob.Y+50, 3, eNoBlock, eAnywhere);
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Ashen

OK, simple thing first:
Since you're using eAnywhere for the movement type, have you got rid of the walkable area? If so, you also need to get rid of the && GetWalkableAreaAt(blahX, blahY)) != 0 parts of the conditions. Alternatively - get rid of eAnywhere and put the walkable areas in. It won't interfere witht the characters (being 1st person) and it limits the area the blocks can slide in.

I can't see any other thing it could be, unless it's in another part of the code. Try this first, though.
I know what you're thinking ... Don't think that.

Ghostlady

#2
Thanks Ashen, I put the walkable area in and now the blocks are moving.Ã,  Now I am trying to code the part for the end of puzzle condition.Ã,  Using your code from the other post, I am getting an error message of -- '[' expected -- and it is pointing to this line:

Code: ags
Hotspot *hot = Hotspot.GetAtScreenXY(object.x+25,Ã,  object.y-25);Ã,  //Middle of tile


I haven't been able to find in the manual what '*' means next to something.Ã,  Can you explain that to me?

Here is the whole script, can you tell me where I need to add that bracket?
Code: ags
// room script file
int button_pressed=0;
Object *ob;

// called when the puzzle is solved:
function Checksolved() {
Ã,  int correct;
Ã,  int i=1;
Ã,  while (i <= 8) { // or number of slide-pieces
Ã,  Ã,  Hotspot *hot = Hotspot.GetAtScreenXY(object.X+25,Ã,  object.Y-25);Ã,  //Middle of tile
Ã,  Ã,  if (hot.ID == i) correct ++;
Ã,  Ã,  else correct = 0;
Ã,  Ã,  Ã,  Ã, i ++;
}
 if (correct == 8) { // or number of slide-pieces
Ã,  Display ("you did it");
 }
}


#sectionstart room_bÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_b() {
Ã,  // script for Room: First time player enters screen
StopMusic();
Wait(40);
object[9].Move(268, 202, 5, eNoBlock, eAnywhere);
Wait(40);
object[9].Visible = false;

Ã,  
}
#sectionend room_bÃ,  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
Ã,  // script for Room: Repeatedly execute
Ã,  
Ã,  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 + 50, ob.Y-1) == null && GetWalkableAreaAt(ob.X+50, ob.Y-1) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X+50, ob.Y, 3, eBlock);
Ã,  Ã,  Ã,  Ã,  Checksolved();
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (Object.GetAtScreenXY(ob.X - 50, ob.Y-1) == nullÃ,  && GetWalkableAreaAt(ob.X-50, ob.Y-1) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X-50, ob.Y, 3, eBlock);
Ã,  Ã,  Ã,  Ã,  Checksolved();
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (Object.GetAtScreenXY(ob.X, ob.Y-51) == nullÃ,  && GetWalkableAreaAt(ob.X, ob.Y-51) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X, ob.Y-50, 3, eBlock);
Ã,  Ã,  Ã,  Ã,  Checksolved();
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  else if (Object.GetAtScreenXY(ob.X, ob.Y+49) == nullÃ,  && GetWalkableAreaAt(ob.X, ob.Y+49) != 0) {
Ã,  Ã,  Ã,  Ã,  ob.Move(ob.X, ob.Y+50, 3, eBlock);
Ã,  Ã,  Ã,  Ã,  Checksolved();
Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  ob = null;
Ã,  Ã,  }
Ã,  }
}


#sectionend room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart object0_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function object0_a() {
Ã,  // script for Object 0: Any click on object
object[0].Move(object[0].X + 50,Ã,  object[0].Y,Ã,  3, eBlock, eAnywhere);Ã,  Ã, 
}
#sectionend object0_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
 
#sectionstart on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(int button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (mouse.IsButtonDown(eMouseRight)) {
Ã,  player.ChangeRoom (29); 
Ã,  ClaimEvent();
}
}
#sectionend on_mouse_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Ashen

The '*' operator (in this case) means you're declaring a pointer - here, you're declaring hot as a pointer of the type Hotspot. If you're not familiar with pointers, they're a kind of variable - like you can declare an int, then later on say if (MyInt == 3) ... you can now use hot as a shortcut for Hotspot.GetAtScreenXY(object.x+25,  object.y-25).

Someone - I think monkey_05_06 - wrote out a much better description of pointers somewhere, if you can track it down, or of course there's the Manual entry for anyone not familiar with pointers. However, that really has nothing to do with the main problem, it's just something that might be useful to know.

And you may have noticed, I snuck the second answer in there - where you have object.x and object.y they need to be object.x and object.y - they're right in the thread you linked to, did I get 'em wrong in the demo game?

Incidentally, where you're using if (mouse.IsButtonDown(eMouseRight)) further down, you should - since it's in the on_mouse_click function - be able to use if (button == eMouseRight). No difference, just something I noticed.
I know what you're thinking ... Don't think that.

Ghostlady

#4
Aha, pointers, now it makes sense.Ã,  This is good info to know.Ã, 

object - I should have picked up on that.Ã,  The zip file that I download only contains the code for the slider movement.Ã,  No "end puzzle" code.Ã,  I copied that from the other post.

I changed my on_mouse_click code per your request :)

Thanks again Ashen, I think this is a go.Ã, 
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

Ashen

'Sugestion', rather than 'request', I think ... It should work fine as is (was, since you've changed it), and that's the main thing. It just seemed odd to me to create on_mouse_click and use a function you could've called in rep_ex.

This is the post I mentioned, if you're interested (along with the one two posts down). It seems a little more ... accessable than the manual description, to me anyway.
I know what you're thinking ... Don't think that.

Ghostlady

I will print this off and put it with my "forum manual".Ã,  It comes in handy when I read something on the forum or see an example and I don't want to go back and search for it later when I want to use it.Ã,  I have a printed copy.Ã,  Interesting about the pointers.Ã, 
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

monkey0506

Heh...Ashen you beat me to the punch again.  I was going to just compile the three posts I've made thus far in regards to what a pointer is and how it is used in AGS, but I decided to make a thread about it, here.  Ghostlady, please feel free to read over this and see if it helps you.  Some of it will be pretty similar to what you have already read, but there is also more that I took from another post, and some that I added just because. ;D

Ghostlady

This is great, thanks monkey.  I wish I new about pointers before.  But now that I know.....

BTW monkey, do you know that your avatar is showing as a broken image?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

monkey0506

As off topic as this is, yes I do know that my avatar image is broken.  I like it that way.  Actually, I just have been too lazy to reupload the image somewhere else ever since I told James he could take my other hosting down since I wasn't REALLY using it...

Annnyyyywaayy....I'm glad that I could help you understand pointers! :)  Helping people really does make you feel good!

Ghostlady

Yes I agree.Ã,  I like helping people too.Ã,  Hopefully someday I can help out here too, when I get all this coding down. :)
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven
Haunting at Cliffhouse

SMF spam blocked by CleanTalk