Jibble

Author Topic: MODULE: [UI] DragDrop 1.0.0: helps to drag things around your AGS game!  (Read 6536 times)

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?
« Last Edit: 04 Jul 2021, 16:34 by Crimson Wizard »

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: Adventure Game Studio
  1.   if ((chara != null) || (obj != null) || (hot != null) || (inv !=null))
  2.   {
  3.    //Room.ProcessClick(mouse.x, mouse.y, eModeUseinv);
  4.    //inv.RunInteraction(eModeUseinv);
  5.    //ProcessClick(mouse.x, mouse.y, eModeUseinv);
  6.    //cJesus.RunInteraction(eModeUseinv);
  7.    //GUI.ProcessClick(mouse.x, mouse.y, eModeUseinv);
  8.   }
  9.  

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.

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: Adventure Game Studio
  1.   if ((chara != null) || (obj != null) || (hot != null))
  2.   {
  3.     Room.ProcessClick(mouse.x, mouse.y, eModeUseinv);
  4.   }
  5.   else if (inv !=null)
  6.   {
  7.     inv.RunInteraction(eModeUseinv);
  8.   }
  9.  

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: Adventure Game Studio
  1. player.ActiveInventory = DragDropCommon._InvItem;
  2.  
« Last Edit: 04 Jul 2021, 20:10 by Crimson Wizard »

Quote
Wrong 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: Adventure Game Studio
  1. if (DragDrop.EvtWantDrop)
  2. {
  3.   cJesus.ActiveInventory = DragDropCommon._InvItem;
  4.  
  5.   if ((chara != null) || (obj != null) || (hot != null))
  6.   {
  7.    ProcessClick(mouse.x, mouse.y, eModeUseinv);
  8.   }
  9.  
  10.   else if (inv != null)
  11.   {
  12.     inv.RunInteraction(eModeUseinv);
  13.   }
  14. }
  15.  

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.


« Last Edit: 05 Jul 2021, 10:52 by Amir »
Truly, truly, i say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

  inventory 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?

Quote
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.

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

Quote
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?

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: Adventure Game Studio
  1. function iBrot_UseInv()
  2. {
  3. if (cJesus.ActiveInventory == iHonig)
  4. {
  5.   aBrotmithonig.Play(eAudioPriorityNormal, eOnce);
  6.   Wait(80);
  7.   cJesus.LoseInventory(iBrot);
  8.   cJesus.LoseInventory(iHonig);
  9.   cJesus.AddInventory(iBrotmithonig);
  10.  
  11. }  
  12. else
  13. {
  14.      int i;
  15.     i = Random(3);
  16.     if (i == 0) cJesus.Say("Das ist eine bizarre, teuflische Idee.");
  17.     if (i == 1) cJesus.Say("Wahrlich, wahrlich, ich sage dir: Das geht nicht.");
  18.     if (i == 2) cJesus.Say("Versuche das nicht, sonst landest du in der Hölle.");
  19.     if (i == 3) cJesus.Say("Du sollst den Herrn, deinen Gott nicht versuchen. Das geht doch nicht.");  
  20. }  
  21. }
  22.  

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.

Quote
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.

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: Adventure Game Studio
  1.   else if (DragDrop.EvtWantDrop)
  2.   {
  3.     InventoryItem* item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y); // <-------------
  4.     if (item != null) // <-----------------------------------------------------------------------------
  5.       Display("item under: %s",item.Name); // <-------------------------------------------------
  6.  
  7.     InvWindow* drop_to = GetInvWindowUnderObject(o_x, o_y, o_w, o_h);
  8.     if (drop_to != null && ItemOrigin != null && drop_to != ItemOrigin)
  9.     {
  10.       ItemOrigin.CharacterToUse.LoseInventory(DragDropCommon._InvItem);
  11.       drop_to.CharacterToUse.AddInventory(DragDropCommon._InvItem);
  12.     }
  13.   }
  14.  

This displays inventory item's name under the mouse cursor every time you drop something on it.
« Last Edit: 05 Jul 2021, 20:30 by Crimson Wizard »

Hmm, I have got one idea.

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

Code: Adventure Game Studio
  1.   if (inv != null)
  2.   {
  3.     inv.RunInteraction(eModeUseinv);
  4.   }
  5.   else if ((chara != null) || (obj != null) || (hot != null))
  6.   {
  7.    ProcessClick(mouse.x, mouse.y, eModeUseinv);
  8.   }
  9.  


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: Adventure Game Studio
  1.   else if ((chara != null) || (obj != null) || (hot != hotspot[0]))
  2.  
« Last Edit: 05 Jul 2021, 20:37 by Crimson Wizard »

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.

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: Adventure Game Studio
  1. if ((DragDrop.EvtDragStarted) || (DragDrop.EvtDropped))
  2.   {
  3.     player.ActiveInventory = null;
  4.   }
  5.  

or alone

Code: Adventure Game Studio
  1. if (DragDrop.EvtDropped)
  2.   {
  3.    player.ActiveInventory = null;  
  4.   }
  5.  

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.

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?

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.

I cannot tell without seeing full code of rep exec.

I cannot tell without seeing full code of rep exec.

Ok.

Code: Adventure Game Studio
  1.  
  2. Hotspot* prevH;
  3.  
  4. function repeatedly_execute()
  5. {  
  6.  
  7.  int x = mouse.x -280;
  8.  int y = mouse.y -115;
  9.   InventoryItem*ii = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  10.   Label*lbl = gGui1.Controls[0].AsLabel;
  11.   String text;
  12.   if (ii) text = ii.Name;
  13.   else text = Game.GetLocationName(mouse.x, mouse.y);
  14.  
  15.  gGui1.SetPosition(x, y);  // name over verbcoins
  16.  
  17.  
  18.  
  19. Character *chara = Character.GetAtScreenXY(mouse.x, mouse.y);
  20. Object *obj = Object.GetAtScreenXY(mouse.x, mouse.y);
  21. Hotspot *hot = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  22. InventoryItem *inv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  23.  
  24. if (DragDrop.EvtWantDrop)
  25. {
  26.  
  27.   cJesus.ActiveInventory = DragDropCommon._InvItem;
  28.  
  29.   if ((chara != null) || (obj != null) || (hot != hotspot[0]))
  30.   {
  31.    ProcessClick(mouse.x, mouse.y, eModeUseinv);
  32.  
  33.   }
  34.  
  35.     else if (inv != null)
  36.   {
  37.    
  38.     inv.RunInteraction(eModeUseinv);
  39.    
  40.   }
  41. }
  42.  
  43.  
  44. else if (DragDrop.EvtDragStarted) // || (DragDrop.EvtDropped))
  45.   {
  46.     player.ActiveInventory = null;
  47.   }
  48.  
  49.  /*
  50. else
  51. {
  52. player.ActiveInventory = null;  // it works but not a good idea coz the name of objects over the verbcoins doesn't appear any more
  53. }
  54. */
  55.  
  56.  
  57.  
  58.  
  59.  
  60. /////////// Pfeile an Hotspots
  61.  
  62.  
  63. Hotspot* currentH = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  64. if (currentH != prevH) {
  65. int pfeil = currentH.GetProperty("Pfeil");
  66. if (pfeil == 1)
  67. {
  68. mouse.ChangeModeGraphic(eModeWalkto, 236);  
  69. mouse.ChangeModeView(eModeWalkto, 24);
  70. cJesus.Clickable = false;
  71. }  
  72. if (pfeil == 2)
  73. {
  74. mouse.ChangeModeGraphic(eModeWalkto, 232);  
  75. mouse.ChangeModeView(eModeWalkto, 23);  
  76. cJesus.Clickable = false;
  77. }  
  78. if (pfeil == 3)
  79. {
  80. mouse.ChangeModeGraphic(eModeWalkto, 240);  
  81. mouse.ChangeModeView(eModeWalkto, 25);
  82. cJesus.Clickable = false;
  83. }
  84. if (pfeil == 4)
  85. {
  86. mouse.ChangeModeGraphic(eModeWalkto, 228);  
  87. mouse.ChangeModeView(eModeWalkto, 22);
  88. cJesus.Clickable = false;
  89. }
  90.  
  91. if (pfeil == 0 || currentH.ID == 0)
  92. {
  93.  
  94. mouse.ChangeModeGraphic(eModeWalkto, 217);
  95. mouse.ChangeModeView(eModeWalkto, 21);
  96. cJesus.Clickable = true;
  97. }
  98. if ((gMainmenu2.Transparency == 0) && (pfeil == currentH.GetProperty("Pfeil")))
  99. {
  100. mouse.ChangeModeGraphic(eModeWalkto, 217);
  101. }  
  102.  
  103. }
  104. prevH = currentH;
  105.  
  106. }  
  107.  
  108.  
  109.  
Truly, truly, i say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

It works there.

Code: Adventure Game Studio
  1. function repeatedly_execute_always()
  2. {  
  3. if (DragDrop.EvtDropped)
  4. {
  5.   player.ActiveInventory = null;
  6. }
  7.  
  8. }
  9.  

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.

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: Adventure Game Studio
  1. if (DragDrop.EvtWantDrop)
  2. {
  3.   cJesus.ActiveInventory = DragDropCommon._InvItem;
  4.  
  5.   if ((chara != null) || (obj != null) || (hot != hotspot[0]))
  6.   {
  7.    ProcessClick(mouse.x, mouse.y, eModeUseinv);
  8.   }  
  9.   else if (inv != null)
  10.   {
  11.     inv.RunInteraction(eModeUseinv);
  12.   }
  13.  
  14.   cJesus.ActiveInventory = null; // <---------------------
  15. }
  16.  

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

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.

Quote
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.

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.

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: Adventure Game Studio
  1. function ihoney_UseInv()
  2. {
  3. if (cJesus.ActiveInventory == ihoney)
  4. {
  5.  // do nothing  
  6. }
  7. }
  8.  

But I have 60 inventory items. Do you have a quicker solution?
« Last Edit: 11 Jul 2021, 17:10 by Amir »
Truly, truly, i say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.

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: Adventure Game Studio
  1.   else if (inv != null)
  2.   {
  3.     inv.RunInteraction(eModeUseinv);
  4.   }
  5.  
so you could probably also test
Code: Adventure Game Studio
  1.   else if (inv != null && inv != cJesus.ActiveInventory)
  2.   {
  3.     inv.RunInteraction(eModeUseinv);
  4.   }
  5.  

Oh, I'm stupid. Thank u so much.
Truly, truly, i say to you, blessed are those who play adventure games, for theirs is the kingdom of heaven.