(Self-Solved) How can I drag Char1's inventory item to Char2's inventory?

Started by Vault15, Fri 19/10/2012 01:41:24

Previous topic - Next topic

Vault15

I figured it out. I don't know how to delete posts.

Here is just a small part of the code. The rest is more specific for my game.

if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) == LeftHand && mouse.Mode == eModeUseinv && LHITEMSET != 1)
  {
    InventoryChar1.AddInventory(cEgo.ActiveInventory);
    cEgo.LoseInventory(cEgo.ActiveInventory);
    LHITEMSET = 1;
    InventoryChar1.SetAsPlayer();
  }

As for the rest, this post helped me a great deal as well as my more recent post:

http://www.adventuregamestudio.co.uk/forums/index.php?topic=46243.msg621216#msg621216

Khris

The command is GUI.GetAtScreenXY(...), with the GUI part actually being "GUI", not the name of some GUI that might or might not be there. It'll still work how you're doing it because apparently the method isn't static, but it's bad form and makes no sense.

Vault15

Quote from: Khris on Sat 20/10/2012 22:00:11
The command is GUI.GetAtScreenXY(...), with the GUI part actually being "GUI", not the name of some GUI that might or might not be there. It'll still work how you're doing it because apparently the method isn't static, but it's bad form and makes no sense.

Please explain what you mean. This method has worked flawlessly to detect if a mouse is at certain parts of a gui or an entire gui. What should I change in my code? Keep in mind I have about 120 lines of code just for the inventory system so far (still have a lot needed) including that little section I posted. I didn't want to post the bulk of it.

Khris

Like I said, LeftHand.GetAtScreenXY(mouse.x, mouse.y) is supposed to be GUI.GetAtScreenXY(mouse.x, mouse.y), not as in "the name of the gui here" like with non-static methods but the actual letters "GUI".
The functions returns the GUI under the mouse or null, so calling it like that, while it may work, is bad form and makes no sense.

GUI is the gui class, and LeftHand is an instance of it. .GetAtScreenXY isn't a method that does something to a specific GUI, like for instance .SetPosition; it should be a static method that can only be called like it's supposed to. Unfortunately it isn't, and not only will it compile, the end result is the same. But you shouldn't use it like that, if only to avoid other people seeing that and adopting it.

Vault15

Ahh okay, gotcha =]. Thanks for explaining that, it wasn't quite clicking. Good to know so I don't help someone out technically wrong (as you said).

I went ahead and replaced all of the mistypes. It's funny 'cause I'd always stare at that code and be like "why the hell is this working?" then shrugged it off when it actually worked consistently =P

Vault15

Quote from: Khris on Sun 21/10/2012 10:53:42

GUI is the gui class, and LeftHand is an instance of it. .GetAtScreenXY isn't a method that does something to a specific GUI, like for instance .SetPosition; it should be a static method that can only be called like it's supposed to. Unfortunately it isn't, and not only will it compile, the end result is the same. But you shouldn't use it like that, if only to avoid other people seeing that and adopting it.

Actually it turns out I was using the commands with inventory windows as well. What is supposed to be here instead of "GUI.GetAtScreenXY"? This isn't a Gui, it's an inventory window, so what is the proper form?

Code: AGS

if(RightHand.GetAtScreenXY(mouse.x, mouse.y) == RightHand && RHITEMSET == 1)
  {
    InventoryChar2.SetAsPlayer();
  }


Crimson Wizard

Quote from: Khris on Sun 21/10/2012 10:53:42
.GetAtScreenXY isn't a method that does something to a specific GUI, like for instance .SetPosition; it should be a static method that can only be called like it's supposed to. Unfortunately it isn't, and not only will it compile, the end result is the same.
AGS rule on static functions seem to be based on C++ rule, rather than, for example, on C# rule. This may be easily checked: if you have a custom struct with static function, you may call that function from both struct's name and variable of that type.

I must agree that the role of static methods would be more comprehensible if it'd be denied to be called as variable's member, but that should be officially stated in AGS script standard (and changed in compiler implementation).


SMF spam blocked by CleanTalk