Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Skeller53

#1
Use Global Ints. Check the manual for information on these, or search the forums for related topics on using Global Ints. I'm sure you'll find what you need.
#2
Perfect! Just what I wanted. Thank you so much.

Don't know how I missed that in the object function list. Of the many services this board provides, one is to get novices like me to approach problems from different angles. It's great.
#3
Is there a way to trigger an action based upon a specific frame in an object's animation? For example, if you want to trigger a collision between object A and object B, but you only want it to occur/be detected on the third frame of object A's animation, is there a way to do that?

As always, many thanks for any help.
#4
I may try that out, Scorpiorus, but as I suspected it sounds like it would be easier to just create the animation of the straw with smoke, and then change the straw to that animation whenever the guy picked it up.

Thanks, Sorpiorus. Good luck, Candle.
#5
I understand how one would make a "smoke" animation, but I'm not certain how one would make the smoke animation appear at the right location in relation to the straw that the character would be holding. I know you could just make an animation including both straw and smoke, but is it possible to make a separate and independent smoke object that would appear and animate at a certain location relative to the straw object (i.e. always at the end of the straw object no matter where the straw object was on the screen)?

I hope it's OK to ask this here. Sorry if you think it should be a different topic.
#6
Success, sort of. Out of sheer frustration, I opened your game and then copied your room as a room into my game. I opened up my game, opened up the new room, changed the background image to mine, added my character in place of roger, changed your objects to objects in my game (changing the room script where necessary to reflect the new objects), and fired it up. Voila! It worked. I now have a room where objects can be grabbed, moved, and otherwise manipulated. I have no idea why this works now and what I had in my other rooms that wouldn't allow your code to work, but there you go. I can now use the room I copied from your game to do what I want. I still have collision issues but I am confident these can be resolved.

I can't thank you enough for your help here. Do you have a problem with me proceeding to create a game basically using a room you created? If so let me know and of course I will stop. If you don't mind, on the other hand, I will certainly give you top credit if and when the game is ever released. Many, many thanks to you Scorpiorus!
#7
And of course your game works perfectly! Thank you so much for all the help you've given me so far. I will use your game and the other advice you've provided to try to get the grabbing function to work in my game. There must be something about my game that won't allow this code to work, and I'll just keep at it and see if I can figure it out. The main thing is that I know it is possible to do.

Thanks again and maybe the next time I post here I'll be announcing success (or more likely asking for help with another problem).
#8
Sorry. I got confused regarding being "called within" as opposed to placed within. Still, with this change below, I get no error message but still can't grab anything. Grrrr.

// room script file

// holds an object number that's under the cursor
// but only if the mouse button is released. (or -1):
// (***used internally!***)
int objectToGrab = -1;

// the object number that's currently being dragged (or -1).
// Use this variable to find out what object is being dragged:
// (***read-only***)
int objectGrabbed = -1;

// object's sprite slot before it's grabbed:
// useful if you want to set object's graphic back
// when the object is dropped:
int objectOrginalSprite = -1;

// mouse button to grab an object with:
int mouseButton = LEFT;

// grabbing is allowed for this cursor mode:
int grabbingCursorMode = MODE_USE;

// This event occurs when we are about to grab an object (number 'objectNum').
// You can decide here whether it's allowed to grab the object.
// You must return 1 if the object can be dragged.
// Otherwise, return 0.
function on_object_grabbed(int objectNum) {
Ã, 
Ã,  Ã,  if (objectNum == 4)Ã,  return 1; // grab hammer
Ã,  Ã,  if (objectNum == 6) return 1; // grab whirlblade
Ã,  Ã, 
Ã,  Ã,  return 0;Ã, 
}

// This event occurs when we are about to drop an object (number 'objectNum').
// You can, for example, stop animation here or play falling animation
// (see MoveObject command), etc.
function on_object_dropped(int objectNum) {
Ã, 
Ã, 
Ã,  Ã,  // the following code stops the hammer object's animating
Ã,  Ã,  // and set its sprite back to normal:
Ã, 
Ã,  Ã,  if (objectNum == 4)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (IsObjectAnimating(4))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetObjectGraphic(objectNum, objectOrginalSprite);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }Ã, 
}

// Calling this function will drop the currently dragged object.
// If there is no one, nothing happens.
function DropObject() {
Ã, 
Ã,  Ã,  if (objectGrabbed != -1)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  on_object_dropped(objectGrabbed);
Ã,  Ã,  Ã,  Ã,  objectOrginalSprite = -1;
Ã,  Ã,  Ã,  Ã,  objectGrabbed = -1;
Ã,  Ã,  }
}
Ã,  Ã, functionÃ,  GrabObject_REP_EXEC() // <-- must be within repeatedly execute;
Ã,  {
Ã,  // Main part of the grabbing object script.
// *** Must be called within repeatedly execute ***
Ã,  Ã,  if (objectGrabbed == -1)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (IsButtonDown(mouseButton))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (GetCursorMode() == grabbingCursorMode)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (on_object_grabbed(objectToGrab) == 1)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectOrginalSprite = GetObjectGraphic(objectToGrab);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectGrabbed = objectToGrab;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectToGrab = -1;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectToGrab = GetObjectAt(mouse.x, mouse.y);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  Ã,  else
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (IsButtonDown(mouseButton))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int object_sprite = GetObjectGraphic(objectGrabbed);
Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int sprite_widthÃ,  = GetGameParameter(GP_SPRITEWIDTH,Ã,  object_sprite, 0, 0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int sprite_height = GetGameParameter(GP_SPRITEHEIGHT, object_sprite, 0, 0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int newX = GetViewportX() + (mouse.x - sprite_width / 2);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int newY = GetViewportY() + (mouse.y + sprite_height / 2);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetObjectPosition(objectGrabbed, newX, newY);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, DropObject();
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }
function on_key_press(int key) {
Ã, 
Ã,  Ã,  // the following code starts object animation if
Ã,  Ã,  // 'space' key is pressed and provided:
Ã,  Ã,  //Ã,  1. grabbed object is the hammer;
Ã,  Ã,  //Ã,  2. object isn't animating.

Ã,  Ã,  if (key == 32)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (objectGrabbed == 4)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (IsObjectAnimating(4)==0)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetObjectView(4, 14);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  AnimateObject(4, 2, 0, 0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }

Ã,  }

}


#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
Ã,  // script for room: Repeatedly execute
GrabObject_REP_EXEC(); // invoke the function

}Ã,  Ã, 

#sectionend room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
#9
Sorry for being so slow to grasp this, but I do appreciate you for being so patient with me. I'll move that code section around this afternoon and let you know.


OK, I guess I'm blind as well as slow. I get the dreaded "Nested functions not supported you probably forgot to close a brace" error message (at the "functionÃ,  GrabObject_REP_EXEC()" line) when I try to save the following code, which I only changed to include the "functionÃ,  GrabObject_REP_EXEC()" within the repeatedly execute function (I took the ending brace from one place and put it at the end of the section). The braces all match according to the script editor. Where have I gone astray this time, oh wise one . . .


// room script file

// holds an object number that's under the cursor
// but only if the mouse button is released. (or -1):
// (***used internally!***)
int objectToGrab = -1;

// the object number that's currently being dragged (or -1).
// Use this variable to find out what object is being dragged:
// (***read-only***)
int objectGrabbed = -1;

// object's sprite slot before it's grabbed:
// useful if you want to set object's graphic back
// when the object is dropped:
int objectOrginalSprite = -1;

// mouse button to grab an object with:
int mouseButton = LEFT;

// grabbing is allowed for this cursor mode:
int grabbingCursorMode = MODE_USE;

// This event occurs when we are about to grab an object (number 'objectNum').
// You can decide here whether it's allowed to grab the object.
// You must return 1 if the object can be dragged.
// Otherwise, return 0.
function on_object_grabbed(int objectNum) {
Ã, 
Ã,  Ã,  if (objectNum == 4)Ã,  return 1; // grab hammer
Ã,  Ã,  if (objectNum == 6) return 1; // grab whirlblade
Ã,  Ã, 
Ã,  Ã,  return 0;Ã, 
}

// This event occurs when we are about to drop an object (number 'objectNum').
// You can, for example, stop animation here or play falling animation
// (see MoveObject command), etc.
function on_object_dropped(int objectNum) {
Ã, 
Ã, 
Ã,  Ã,  // the following code stops the hammer object's animating
Ã,  Ã,  // and set its sprite back to normal:
Ã, 
Ã,  Ã,  if (objectNum == 4)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (IsObjectAnimating(4))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetObjectGraphic(objectNum, objectOrginalSprite);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }Ã, 
}

// Calling this function will drop the currently dragged object.
// If there is no one, nothing happens.
function DropObject() {
Ã, 
Ã,  Ã,  if (objectGrabbed != -1)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  on_object_dropped(objectGrabbed);
Ã,  Ã,  Ã,  Ã,  objectOrginalSprite = -1;
Ã,  Ã,  Ã,  Ã,  objectGrabbed = -1;
Ã,  Ã,  }
}
#sectionstart room_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
Ã,  // script for room: Repeatedly execute
Ã,  Ã,  Ã, functionÃ,  GrabObject_REP_EXEC() // <-- must be within repeatedly execute;
Ã,  {
Ã,  // Main part of the grabbing object script.
// *** Must be called within repeatedly execute ***
Ã,  Ã,  if (objectGrabbed == -1)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (IsButtonDown(mouseButton))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (GetCursorMode() == grabbingCursorMode)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (on_object_grabbed(objectToGrab) == 1)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectOrginalSprite = GetObjectGraphic(objectToGrab);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectGrabbed = objectToGrab;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectToGrab = -1;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  objectToGrab = GetObjectAt(mouse.x, mouse.y);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  Ã,  else
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (IsButtonDown(mouseButton))
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int object_sprite = GetObjectGraphic(objectGrabbed);
Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int sprite_widthÃ,  = GetGameParameter(GP_SPRITEWIDTH,Ã,  object_sprite, 0, 0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int sprite_height = GetGameParameter(GP_SPRITEHEIGHT, object_sprite, 0, 0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int newX = GetViewportX() + (mouse.x - sprite_width / 2);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  int newY = GetViewportY() + (mouse.y + sprite_height / 2);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetObjectPosition(objectGrabbed, newX, newY);
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  else
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã, DropObject();
Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  }
function on_key_press(int key) {
Ã, 
Ã,  Ã,  // the following code starts object animation if
Ã,  Ã,  // 'space' key is pressed and provided:
Ã,  Ã,  //Ã,  1. grabbed object is the hammer;
Ã,  Ã,  //Ã,  2. object isn't animating.

Ã,  Ã,  if (key == 32)
Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  if (objectGrabbed == 4)
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (IsObjectAnimating(4)==0)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  SetObjectView(4, 14);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  AnimateObject(4, 2, 0, 0);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  }
Ã, Ã,  Ã, }

Ã,  }

}


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

I'm not getting any error messages, but I can't grab anything either. Here I'm trying to grab a hammer, and I've also identified another object (whirlblade). I know this is something basic that I have or haven't done. Here is the script for my room:


// room script file

// holds an object number that's under the cursor
// but only if the mouse button is released. (or -1):
// (***used internally!***)
int objectToGrab = -1;

// the object number that's currently being dragged (or -1).
// Use this variable to find out what object is being dragged:
// (***read-only***)
int objectGrabbed = -1;

// object's sprite slot before it's grabbed:
// useful if you want to set object's graphic back
// when the object is dropped:
int objectOrginalSprite = -1;

// mouse button to grab an object with:
int mouseButton = LEFT;

// grabbing is allowed for this cursor mode:
int grabbingCursorMode = MODE_USE;

// This event occurs when we are about to grab an object (number 'objectNum').
// You can decide here whether it's allowed to grab the object.
// You must return 1 if the object can be dragged.
// Otherwise, return 0.
function on_object_grabbed(int objectNum) {
 
    if (objectNum == 4)  return 1; // grab hammer
    if (objectNum == 6) return 1; // grab whirlblade
   
    return 0; 
}

// This event occurs when we are about to drop an object (number 'objectNum').
// You can, for example, stop animation here or play falling animation
// (see MoveObject command), etc.
function on_object_dropped(int objectNum) {
 
 
    // the following code stops the hammer object's animating
    // and set its sprite back to normal:
 
    if (objectNum == 4)
    {
        if (IsObjectAnimating(4))
        {
            SetObjectGraphic(objectNum, objectOrginalSprite);
        }
    }   
}

// Calling this function will drop the currently dragged object.
// If there is no one, nothing happens.
function DropObject() {
 
    if (objectGrabbed != -1)
    {
        on_object_dropped(objectGrabbed);
        objectOrginalSprite = -1;
        objectGrabbed = -1;
    }
}
#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for room: Repeatedly execute
  }
 
  // Main part of the grabbing object script.
// *** Must be called within repeatedly execute ***
function GrabObject_REP_EXEC() {
 
    if (objectGrabbed == -1)
    {
        if (IsButtonDown(mouseButton))
        {
            if (GetCursorMode() == grabbingCursorMode)
            {
                if (on_object_grabbed(objectToGrab) == 1)
                {
                    objectOrginalSprite = GetObjectGraphic(objectToGrab);
                    objectGrabbed = objectToGrab;
                    objectToGrab = -1;
                }
            }
        }
        else
        {
            objectToGrab = GetObjectAt(mouse.x, mouse.y);
        }
    }
    else
    {
        if (IsButtonDown(mouseButton))
        {
            int object_sprite = GetObjectGraphic(objectGrabbed);
       
            int sprite_width  = GetGameParameter(GP_SPRITEWIDTH,  object_sprite, 0, 0);
            int sprite_height = GetGameParameter(GP_SPRITEHEIGHT, object_sprite, 0, 0);
             
            int newX = GetViewportX() + (mouse.x - sprite_width / 2);
            int newY = GetViewportY() + (mouse.y + sprite_height / 2);
               
            SetObjectPosition(objectGrabbed, newX, newY);
        }
        else
        {
           DropObject();
        }     
    }
}


function on_key_press(int key) {
 
    // the following code starts object animation if
    // 'space' key is pressed and provided:
    //  1. grabbed object is the hammer;
    //  2. object isn't animating.

    if (key == 32)
    {
        if (objectGrabbed == 4)
        {
            if (IsObjectAnimating(4)==0)
            {
                SetObjectView(4, 14);
                AnimateObject(4, 2, 0, 0);
            }
        }
   }
}
#11
Thank you, Scorpiorus. I will try that and let you know how it works out.

Just a couple of basic and I hope not too silly questions. Where it says OBJECT_HAMMER, is the object number expected? I'm trying to figure out if this code will work for all objects in the room, or if separate code is needed for each object.Ã,  I have the same question about HAMMER_SPRITE. Is a specific sprite number expected here?

Thanks a bunch. I'm going to try the code out later tonight and report back.
#12
I've searched the manual and the forums and maybe I've missed this, but I'd like to be able to pick up an object (say, with a cursor that looks like a hand) and use it on a character or another object. For example, I have an object that is a hammer. I want to physically grab it with the cursor hand and move it to the character, then initiate an animation that hits the character over the head, or on the foot, etc. Is there a way to do this?

By the way, AGS is wonderful! Thanks to the creator and all the contributors in the forum.
SMF spam blocked by CleanTalk