MODULE: DragDrop 1.1.0: helps to drag things around your AGS game!

Started by Crimson Wizard, Mon 14/03/2016 00:09:54

Previous topic - Next topic

Crimson Wizard

Quote from: Amir on Sun 04/07/2021 14:04:07
Hi, I wrote something and I can now interact with hotspots,objects and characters but wrong interaction and inventory items don't interact with other inventory items. Do u know what's wrong?

First of all, I imagine the code above is not your real code, because there are commands outside of a function?

Regarding the problem, Room.ProcessClick does not interact with the inventory items, because they are not inside the room. For them you got to do GUI.ProcessClick, or just call inv.RunInteraction(eModeUseinv);

I did not understand the part about "wrong interaction", could you explain more?

Amir

Oh, sorry, I made a mistake when I was trying to design my post here. I edited it.

GUI.ProcessClick is new to me but it dosn't work, I tried inv.RunInteraction(eModeUseinv); before but I'm getting an error "Null pointer referenced"
I tried
Code: ags

  if ((chara != null) || (obj != null) || (hot != null) || (inv !=null))
  {
   //Room.ProcessClick(mouse.x, mouse.y, eModeUseinv);
   //inv.RunInteraction(eModeUseinv);
   //ProcessClick(mouse.x, mouse.y, eModeUseinv);
   //cJesus.RunInteraction(eModeUseinv);
   //GUI.ProcessClick(mouse.x, mouse.y, eModeUseinv);
  }


Room.ProcessClick, ProcessClick, cJesus.RunInteraction work but wrong interaction I mean, when I have if, else if and else, it ignores the commands in if and else if and prints the commands in else, I mean it only sees "els" and  inventory items still don't interact with other inventory items.  ???
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Sun 04/07/2021 19:48:42
GUI.ProcessClick is new to me but it dosn't work, I tried inv.RunInteraction(eModeUseinv); before but I'm getting an error "Null pointer referenced"

I think at this point it's more a general question of scripting, rather than the use of this module.

You cannot call inv.RunInteraction(eModeUseinv) always, but only if "inv" is valid (inv !=null). You likely will need more if/elseif blocks to handle everything.


Code: ags

  if ((chara != null) || (obj != null) || (hot != null))
  {
    Room.ProcessClick(mouse.x, mouse.y, eModeUseinv);
  }
  else if (inv !=null)
  {
    inv.RunInteraction(eModeUseinv);
  }


Quote from: Amir on Sun 04/07/2021 19:48:42
Room.ProcessClick, ProcessClick, cJesus.RunInteraction work but wrong interaction I mean, when I have if, else if and else, it ignores the commands in if and else if and prints the commands in else

Wrong interactions, as in wrong verb, or wrong inventory item?

If last, how do you normally check for the used item? For example, if you check "player.ActiveInventory", then you simply may set it before running process click to whatever item is being dropped.
Code: ags

player.ActiveInventory = DragDropCommon._InvItem;

Amir

QuoteWrong interactions, as in wrong verb, or wrong inventory item?

Wrong verb.

But with player.ActiveInventory = DragDropCommon._InvItem; it works, cool  :)  inventory items still don't want to interact with other inventory items.

Code: ags

if (DragDrop.EvtWantDrop)
{
  cJesus.ActiveInventory = DragDropCommon._InvItem;
  
  if ((chara != null) || (obj != null) || (hot != null))
  {
   ProcessClick(mouse.x, mouse.y, eModeUseinv);
  }

  else if (inv != null) 
  {
    inv.RunInteraction(eModeUseinv);
  }
}


I made a video of whats happening. I've tried a lot of things but it still doesn't work. I think something is still missing in the code.


Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Mon 05/07/2021 10:50:26inventory items still don't want to interact with other inventory items.

More information is needed.
Does the code ever pass under "else if (inv != null)" ? You may test that either by placing a breakpoint there or "Display" command with some message.
You are running eModeUseinv interaction. Do you have event of that type ("use inventory item on") created for your items?
What is inside these event functions, are there more conditions? Can you post an example of your script?

Amir

QuoteDoes the code ever pass under "else if (inv != null)" ? You may test that either by placing a breakpoint there or "Display" command with some message.

Good question. I tried Display command, nothing happened, the Display message didn't appear.

QuoteYou are running eModeUseinv interaction. Do you have event of that type ("use inventory item on") created for your items?
What is inside these event functions, are there more conditions? Can you post an example of your script?

Yes, most of them have "use inventory item on" I tried many items with each other with an event and it happens the same as in the video. I'm not just trying money with carrot  ;-D
An example for useing an inventory item with another item: honey with bread.

Code: ags

function iBrot_UseInv()
{
if (cJesus.ActiveInventory == iHonig)
{
  aBrotmithonig.Play(eAudioPriorityNormal, eOnce);
  Wait(80);
  cJesus.LoseInventory(iBrot);
  cJesus.LoseInventory(iHonig);
  cJesus.AddInventory(iBrotmithonig);
  
}  
else
{
     int i;
    i = Random(3);
    if (i == 0) cJesus.Say("Das ist eine bizarre, teuflische Idee."); 
    if (i == 1) cJesus.Say("Wahrlich, wahrlich, ich sage dir: Das geht nicht.");
    if (i == 2) cJesus.Say("Versuche das nicht, sonst landest du in der Hölle.");
    if (i == 3) cJesus.Say("Du sollst den Herrn, deinen Gott nicht versuchen. Das geht doch nicht.");  
}  
}


I think it's up to the module. something is still missing something like player.ActiveInventory = DragDropCommon._InvItem; I read through ur module, tried to understand it, I got half of it but I couldn't find out why the inventory items don't interact with other inventory items.

Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Mon 05/07/2021 19:40:31
QuoteDoes the code ever pass under "else if (inv != null)" ? You may test that either by placing a breakpoint there or "Display" command with some message.

Good question. I tried Display command, nothing happened, the Display message didn't appear.

So, inv is always null, or condition does not work.
The question is why your script does not detect an inventory item at the place of the drop.
Maybe the detection is not correct. Or there's some extra code that prevents this to work.



I made a quick test with the existing Demo game, and added few lines in the 4th room script:
Code: ags

  else if (DragDrop.EvtWantDrop)
  {
    InventoryItem* item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y); // <-------------
    if (item != null) // <-----------------------------------------------------------------------------
      Display("item under: %s",item.Name); // <-------------------------------------------------

    InvWindow* drop_to = GetInvWindowUnderObject(o_x, o_y, o_w, o_h);
    if (drop_to != null && ItemOrigin != null && drop_to != ItemOrigin)
    {
      ItemOrigin.CharacterToUse.LoseInventory(DragDropCommon._InvItem);
      drop_to.CharacterToUse.AddInventory(DragDropCommon._InvItem);
    }
  }


This displays inventory item's name under the mouse cursor every time you drop something on it.

Crimson Wizard

Hmm, I have got one idea.

Try changing the order of tests. Test inventory item first, then everything else:

Code: ags

  if (inv != null) 
  {
    inv.RunInteraction(eModeUseinv);
  }
  else if ((chara != null) || (obj != null) || (hot != null))
  {
   ProcessClick(mouse.x, mouse.y, eModeUseinv);
  }



EDIT Also I've just realized that the hotspot test is wrong. You should not compare hot with null, because Hotspot.GetAtScreenXY always returns something.
You got to compare it with hotspot[0], which is "no hotspot"/eraser:
Code: ags

  else if ((chara != null) || (obj != null) || (hot != hotspot[0]))

Amir

It's a good thing that I refreshed here and saw your edit. I almost wanted to try something complicated. Now it works  (laugh) ur right about hot != null, I have often read it here in the forum but forgot it. Such a little thing can cause disaster like a butterfly effect.

There are a few problems but it has nothing to do with the module. I think I can solve them on my own or I would create a new thread. the biggest problem would be the Android port but it doesn't matter if it doesn't work. Programming with AGS is fun.

Thank u so much for ur patience and help.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Amir

Sorry for bothering again. I'm trying something but it dosn't work. I want the selected inventory item to disappear after the interaction or dropping, both in the inventory with inventory items and outside with objects.

I used if (DragDrop.EvtDragStarted) player.ActiveInventory = null; so that it's not chosen twice like in the video. This works fine.

in repeatedly execute
Code: ags

if ((DragDrop.EvtDragStarted) || (DragDrop.EvtDropped))
  {
    player.ActiveInventory = null;
  }


or alone

Code: ags

if (DragDrop.EvtDropped)
  {
   player.ActiveInventory = null;   
  } 


The inventory item doesn't go away.

Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Mon 05/07/2021 23:48:47
I want the selected inventory item to disappear after the interaction or dropping, both in the inventory with inventory items and outside with objects

When you say "dissapear" do you mean dissapear from cursor, or dissapear from player's inventory?

Amir

Quote from: Crimson Wizard on Tue 06/07/2021 00:33:50
Quote from: Amir on Mon 05/07/2021 23:48:47
I want the selected inventory item to disappear after the interaction or dropping, both in the inventory with inventory items and outside with objects

When you say "dissapear" do you mean dissapear from cursor, or dissapear from player's inventory?

From cursor  ;-D
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.


Amir

Quote from: Crimson Wizard on Tue 06/07/2021 12:33:27
I cannot tell without seeing full code of rep exec.

Ok.

Code: ags


Hotspot* prevH;

function repeatedly_execute() 
{  
  
 int x = mouse.x -280;
 int y = mouse.y -115; 
  InventoryItem*ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  Label*lbl = gGui1.Controls[0].AsLabel;
  String text;
  if (ii) text = ii.Name;
  else text = Game.GetLocationName(mouse.x, mouse.y);
  
 gGui1.SetPosition(x, y);  // name over verbcoins
  

 
Character *chara = Character.GetAtScreenXY(mouse.x, mouse.y);
Object *obj = Object.GetAtScreenXY(mouse.x, mouse.y);
Hotspot *hot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
InventoryItem *inv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

if (DragDrop.EvtWantDrop)
{

  cJesus.ActiveInventory = DragDropCommon._InvItem;
  
  if ((chara != null) || (obj != null) || (hot != hotspot[0]))
  {
   ProcessClick(mouse.x, mouse.y, eModeUseinv);

  }
  
    else if (inv != null) 
  {
    
    inv.RunInteraction(eModeUseinv);
    
  }
}
 

else if (DragDrop.EvtDragStarted) // || (DragDrop.EvtDropped))
  {
    player.ActiveInventory = null;
  }
 
 /*
else
{
player.ActiveInventory = null;  // it works but not a good idea coz the name of objects over the verbcoins doesn't appear any more
}
*/





/////////// Pfeile an Hotspots


Hotspot* currentH = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
if (currentH != prevH) {
int pfeil = currentH.GetProperty("Pfeil");
if (pfeil == 1)
{
mouse.ChangeModeGraphic(eModeWalkto, 236);  
mouse.ChangeModeView(eModeWalkto, 24);
cJesus.Clickable = false;
}  
if (pfeil == 2)
{
mouse.ChangeModeGraphic(eModeWalkto, 232);  
mouse.ChangeModeView(eModeWalkto, 23);  
cJesus.Clickable = false;
}  
if (pfeil == 3)
{
mouse.ChangeModeGraphic(eModeWalkto, 240);  
mouse.ChangeModeView(eModeWalkto, 25); 
cJesus.Clickable = false;
}
if (pfeil == 4)
{
mouse.ChangeModeGraphic(eModeWalkto, 228);  
mouse.ChangeModeView(eModeWalkto, 22);
cJesus.Clickable = false;
}

if (pfeil == 0 || currentH.ID == 0) 
{

mouse.ChangeModeGraphic(eModeWalkto, 217);
mouse.ChangeModeView(eModeWalkto, 21);
cJesus.Clickable = true;
} 
if ((gMainmenu2.Transparency == 0) && (pfeil == currentH.GetProperty("Pfeil")))
{
mouse.ChangeModeGraphic(eModeWalkto, 217);
}  

}
prevH = currentH;

}   


Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Amir

It works there.

Code: ags

function repeatedly_execute_always() 
{   
if (DragDrop.EvtDropped)
{
  player.ActiveInventory = null;
}

}


But I don't know if this is its right place.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Amir, sorry for not responding earlier.

I don't think the repeatedly_execute_always is a "wrong" place, with that it may work all the time regardless of other things you do in rep-exec.

Looking at the big repeatedly_execute() function, my first thought is that you could place it under the "if (DragDrop.EvtWantDrop)" section, after calling all the ProcessClick/RunInteraction:
Code: ags

if (DragDrop.EvtWantDrop)
{
  cJesus.ActiveInventory = DragDropCommon._InvItem;

  if ((chara != null) || (obj != null) || (hot != hotspot[0]))
  {
   ProcessClick(mouse.x, mouse.y, eModeUseinv); 
  }  
  else if (inv != null) 
  {
    inv.RunInteraction(eModeUseinv);
  }

  cJesus.ActiveInventory = null; // <---------------------
}


But maybe you tried that already and it did not work?

Amir

Thanks for ur returning and answer. I thought you gave up  ;-D

I think I've tried this before because what's happening with this method has happened to me before, and what's happening is that it's wrong interaction again. It goes in the function directly to ELSE again and ignores IF and ELSE IF. Our example: Bread with honey, Jesus says: it doesn't work, instead of combining them together.

QuoteI don't think the repeatedly_execute_always is a "wrong" place, with that it may work all the time regardless of other things you do in rep-exec.

Okay. I will leave it there then. It doesn't cause any problems so far. I think that is the only solution. I don't know why but that is what it looks like.
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Amir

There is also a problem that I didn't notice before. The inventory items interact with themselves (laugh) especially if you click on it once. I can't find where to check if an inventory item is on itself so that nothing happens.

I have this solution:

Code: ags

function ihoney_UseInv()
{
if (cJesus.ActiveInventory == ihoney)
{
 // do nothing  
}
}


But I have 60 inventory items. Do you have a quicker solution?
Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

Crimson Wizard

Quote from: Amir on Sun 11/07/2021 17:07:28
There is also a problem that I didn't notice before. The inventory items interact with themselves (laugh) especially if you click on it once. I can't find where to check if an inventory item is on itself so that nothing happens.

Ah right, so, you have this code above, under condition "if (DragDrop.EvtWantDrop)":
Code: ags

  else if (inv != null) 
  {
    inv.RunInteraction(eModeUseinv);
  }

so you could probably also test
Code: ags

  else if (inv != null && inv != cJesus.ActiveInventory) 
  {
    inv.RunInteraction(eModeUseinv);
  }

Amir

Truly, truly, I say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

SMF spam blocked by CleanTalk