Object drag and put into right place

Started by alimpo83, Sat 09/09/2006 00:08:04

Previous topic - Next topic

alimpo83

Hi all. I've looked the foruns and found the solution for other AGS versions prior to 2.7x. When I load them in AGS 2.71 they work. If I try to paste the text - script -  to my game it crashes, multiple errors(in ags 2.71 too).

I need help doing this:

I have a puzzle that is missing 3 pieces that need to get into the right places before the next action occurs; if you put the pieces wrong, nothing happens.If you put them right you solve the puzzle.You'll do this by dragging the pieces with left mouse button. Can someone help me?
Thanks!
LIMPO ARTS

Candle

Just lay out the pieces but three of them or hidden till they drag the piece to that spot then hBrownTree.Enabled = true;


Ashen

What are the errors? If they work when 'loaded in', then they CAN work for you and it might be easier to fix the errors, than start over. Either way, knowing exactly what you've already tried, and what sort of errors you're getting would help.

Also, what is the difference between when you 'load them in AGS 2.71', and copy-pasting the script? Is it a module - ans if so why not just use that rather than pasting the code elsewhere.
I know what you're thinking ... Don't think that.

alimpo83

Well I didn't realise that, I never used modules before.

How can I call a module in a room? It's in the room script right? But how?

I know it's a noob question, but please help!
LIMPO ARTS

Ashen

It depends on the module, but generally there'll be functions you can call, just like you would any other. For example, there might be a Drag.Start(); functon you need to use in one of the 'Player enters room' interactions to get it running. It should be documented in the module, or a ReadMe that came with it.
I know what you're thinking ... Don't think that.

alimpo83

Well I decided to use your module HotSpot Combolock. How can I do it?
LIMPO ARTS

Ashen

#6
OK, now you've confused me. That module has NOTHING to do with what you described above, so what are you asking about now?

And again - what code WERE you using, when you sort-of had it working? I know the code for what you want IS on the forums, so if you post what you had, and what the errors where we can maybe get it working as you originally wanted.
I know what you're thinking ... Don't think that.

alimpo83

I said:

"I have a puzzle that is missing 3 pieces that need to get into the right places before the next action occurs" : which is what your module does, but with 4 pieces from what I read! You use numbers but I use symbols, that's not a problem. Forget the copy paste thing I said before. I just need to know HOW to use your module.

Thanks
LIMPO ARTS

Ashen

Ah, OK. That's not quite what the module does. It uses the 4 objects as a display, for a keypad-like combination lock. So, you click on Hotspot 1, and the first object changes to '1'. Click Hotspot 3, and they change to '1' '3', etc, until the four digit code is entered. (It'd be easier to do this with a GUI - as SSH's module does - but this was done as an alternative, for people who can't/don't want to use GUIs.)
The way I understood your problem was more like a jigsaw puzzle - the 3 pieces have to be moved into place - which that module can't handle. If I'm wrong, PM me, and we can work out how to re-work the module to suit your needs, or whether you need to figure out something better.
The basics of using it as intended are explained in the ReadMe that came with it (although, maybe not that well), but it's been a while since I wrote it so I'll need a bit to re-familiarise myself with how it works, if you ARE going to use it.
I know what you're thinking ... Don't think that.

strazer

Have you tried Scorpiorus' test game from this thread in the Tech Archive? It sounds like what you're after.

Ashen

#10
...

Well, I was kind of assuming that's what was origianlly being used because, yes, it's pretty much exactly what's needed, apart from being pre-OO script. (Unless the test game is OO? Nothing else n the thread seems to be.)

If you haven't tried that, alimpo83, it's probably a LOT easier than messing around with the module, so please ignore my previous post.
I know what you're thinking ... Don't think that.

alimpo83

That Puzzle script would work but most of the functions names changed from 2004 to the latest version and are now obsolete.When I try to compile my game it gives me scripting errors. An example is (IsButtonDown(LEFT)) that is now obsolete and has to be changed to if (mouse.IsButtonDown(eMouseleft))

Well the original script looks like this:

// script for room: Repeatedly execute
 
 
  if (IsButtonDown(LEFT)) {
    if (button_pressed==0) {
      button_pressed = 1;
      ob = GetObjectAt(mouse.x, mouse.y);
     
      if (ob!=-1) {
          int width  = GetGameParameter(GP_SPRITEWIDTH, GetObjectGraphic(ob), 0, 0);
          int height = GetGameParameter(GP_SPRITEHEIGHT, GetObjectGraphic(ob), 0, 0);
         
          //MoveObjectDirect(ob, mouse.x-width/2, mouse.y+height/2, 7);
          //while (IsObjectMoving(ob)) Wait(1);
         
      }
     
    }
  } else {
    button_pressed=0;
    if (ob!=-1) {
      SetObjectBaseline(ob, 0);     
      ob=-1;
     
      int i = 1; correct = 1;
      while (i < _THE_NUMBER_OF_OBJECTS_YOU_HAVE_) {
        int width  = GetGameParameter(GP_SPRITEWIDTH, GetObjectGraphic(i), 0, 0);
        int height = GetGameParameter(GP_SPRITEHEIGHT, GetObjectGraphic(i), 0, 0);
        correct=correct*(GetHotspotAt(GetObjectX(i)+width/2, GetObjectY(i)-height/2)==i);
        //Display("object number %d (correct=%d)", i, correct); //debug
        i++;
      }
   
      if (correct == 1) {
        on_puzzle_solved(); //call an event function
      }
   
    }
  }
   

  if (ob != -1) {
    int width  = GetGameParameter(GP_SPRITEWIDTH, GetObjectGraphic(ob), 0, 0);
    int height = GetGameParameter(GP_SPRITEHEIGHT, GetObjectGraphic(ob), 0, 0);
    SetObjectBaseline(ob, game.room_height);
    SetObjectPosition(ob, mouse.x-width/2, mouse.y+height/2);
  }



Could you guys tell me what I have to change for it to work?
LIMPO ARTS

strazer

Btw, you can allow old-style commands by unchecking "Enforce object-oriented scripting" in the General Settings.

alimpo83

#13
I'll try and report back soon!

EDIT:
Finally got it, after doing what you said and changing just a bit of code! Thanks. BTW, I can use both old style and new style code types right? The engine will compile the same way?
LIMPO ARTS

Ashen

Provided you've got the 'Enforce OO scripting' option unchecked, you can mix up the styles as much as you want, and it should still compile. As a matter of good practice, however, you should really stick with one - it makes it less confusing when you come to re-read your code. The 'new' commands should be linked in the manual, when you look up the obsolete versions (e.g. looking up GetObjectAt will direct you to Object.GetAtScreenXY), so it shouldn't be that hard to find the commands you need.

For now, though, it's good to hear you've got it working!
I know what you're thinking ... Don't think that.

alimpo83

I plan on using only the new function spelling, and the old only when I use old modules and pieces of code I find here so that I don't need to change everything. Thanks again!  :D
LIMPO ARTS

SMF spam blocked by CleanTalk