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 - AndFisher

#1
Ahh, excellent!

I have got it working now thanks to you. ( I thought it wasn't but I was setting the view_x and view_y to an area just out of the walkable area!)

Many thanks to Khris and to everyone else that lent their time to helping me figure this out.

Andrew.
#2
getInteractable() only returns an object because I have only got that far, I was hoping to rework it once I got the basic functionality to get Hotspot, Character and location.

The first (item != null) only sets the int id as the object's ID, otherwise it is defaulted to -2

-2 User's attention is nothing
-1 User's attention is where the use has clicked, but isn't an interactible area
0 User's attention is object ID 0. etc.

The script then continues on from
Code: ags
if (id == mPlayer.attention)


I would probably change this after I get the functionality working, so that it uses a unique identifier so there is no error between Hotspot Charater and Object IDs. I originally wanted to use item.Name, but this returned the description of the object, i.e. "Blue mug", which is not ideal as there might be an istance where mulitple objects have the same description


Anybody have any clue why it doesn't trigger on a second click (still behaves like blocking script)


Thanks
#3
Thanks to everyone for replying

I have tried something different :

Code: ags

struct customPlayer {
  int attention; // This characters focus
  Character* me; // This character
};

customPlayer mPlayer;
export mPlayer;


Object* getInteractable(int x, int y){
    Object* i = Object.GetAtScreenXY(x, y);
    return i;
}

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button)
{

  int id = -1;

  Object* item = getInteractable(mouse.x, mouse.y);
  if (item != null)
    id = item.ID;
    
    if (id == mPlayer.attention) {
      // do nothing
    } else {
        mPlayer.me.StopMoving();
        
        // Start from scratch
        int walkToX;
        int walkToY;
        
        if (item != null) {
          walkToX = item.GetProperty("view_x");
          walkToY = item.GetProperty("view_y");
        } else {
          walkToX = mouse.x;
          walkToY = mouse.y;
        }
        mPlayer.attention = id;
        mPlayer.me.Walk(walkToX, walkToY, eNoBlock);
        while(mPlayer.me.Moving) {
          Wait(1);
          if(mPlayer.attention != id) {
            mPlayer.attention = -2;
            return;
          }
        }
       if(id == mPlayer.attention && walkToX == mPlayer.me.x && walkToY == mPlayer.me.y) { 
         mPlayer.attention = -2;
         Display("Pick up object");
         ProcessClick(walkToX, walkToY,  mouse.Mode);
       }
    }
    

}
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


I have added to the item schema view_x and view_y co-ords for where the player should walk to.

It doesn't work properly, it works as a blocking script. I cannot interrupt the walk cycle.


Khris - I have looked at your module and it looks good, but would like to have a try first ;) Then I can understand my mistake. Cheers though
#4
Heres some code, this causes Undefined Token, the other way round causes Undefined Symbol

Thanks :)


// MY FUNCTION
function movingToXY(int x, int y) {
 player.Walk(x, y);
   int event;
   while(player.Moving && event==0){
     if (Mouse.IsButtonDown(eMouseLeft))
       event = eMouseLeft;
     if (Mouse.IsButtonDown(eMouseRight))
       event = eMouseRight;
     Wait(1);
   }
   if(event){
     on_mouse_click(event);
     //Interrupted
   } else {
     ProcessClick(x, y, mouse.Mode);
   }
   if (player.x==x && player.y==y){
     //Got there
     return 1;
   } else {
     // Never got there
     return 0;
   }

}

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
 if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
 {
 }

 if (movingToXY(mouse.x, mouse.y))
   Display("got item");

 }
}
#5
Hi all!

I've had a problem, I was trying to add a call to a function, say on mouse click. The function i have called runs, but if certain conditions are met a call back to on mouse click may be required.

The problem is, if my customs function is defined above the on mouse click function I get an undefined token error when I try to compile, or if the on mouse click is defined first I get an undefined symbol error.

Is there a way to do this? I didn't find much in the Wiki apart from scripting for absolute beginners.

I have programmed in other OO languages before, and it seems alien to me that a function must be defined before it is referenced anywhere else in the script. Of course it should be defined before a call to it is executed however. Unless I have totally missed something  ???

I was hoping someone could point me towards the solution and enlighten me to the best practice for where to put my custom scripts.

Thanks in advance to anyone that can help me.

Andrew.
SMF spam blocked by CleanTalk