How to exchange and move items in a backpack Lattice

Source: Internet
Author: User

 

Background ~ Someone mentioned this in the QQ group, and I needed another one. So I wrote this article.

 --  Main. Lua  Require   "  Main_box  "  --  It is best to write a backpack lattice as a class  --  --------------------------  --  Main_box.lua Box = {}  --  Initialize a grid of 6*4 data records For N = 1 , 6   Do     For I = 1 , 4   Do  Box [N] [m] = {ID = 0               --  Item ID Boxline = 70 , -- I use a square lattice with a side length of 70 XP. Light = False        --  Highlighted border    End  End  --  Boxin is a put function.  Function  Boxin (ID)  Local Full = True     For N = 1 , 6   Do       For I = 1 , 4   Do           If (Box [N] [M]. ID = 0 ) Then  Box [N] [M]. ID = Id full = False           End        End     End  If (Full) Then --  Given in fullCode  End  End  --  Add item Boxin ( 1  ) Boxin (  2 )

 

Then the question is someone in the QQ Group asked: "How can I exchange items? "
First, write the "joystick" of an item. What do you mean?
It is the one that records the selected item data when the cursor (or mouse) selects an item.

UB = {}--The "joystick" usebox of the itemIf(First, check whether the cursor is in the package area after the cursor is clicked)And(The cursor position is detected here, or the cursor position in the package area is determined)ThenLocalX, Y =Here we return the position after the cursor is rounded up or the location after the mouse is rounded up ub. Out.= Box [X], box [X], box [x] [Y]. ID--The computer knows what you choose.Box [x] [Y]. Light =True--Highlight the selected item--[[For a mouse operation, you can add a cache to show the moving items at the mouse position and hide the picture of the moved items.]

Next, place or exchange items.
When the cursor is determined at the new position or the left button is released at the new position
That is, you can call the function to determine the location
* Be sure to add the same judgment as the original location.

 

 

 --  The moment when the cursor is determined, or the moment when the left mouse is released, the item is exchanged or placed.  If (......) Then  --  Newx and newy indicate the new location UB. ID = newx, newy, box [newx] [newy]. ID --  Get item ID Box [newx] [newy]. ID = ub. ID --  Alternate old and new Box [ub. x] [ub. Y]. ID = ub. ID --  If the new one is empty, it is equivalent to moving the location. UB. X, UB. Y, UB. ID = newx, newy, UB. ID--  The selected grid changes.  --  There are also some changes to the cursor position.  --  I will not write anything about the highlighted border.  .........  End 

That's it.
I feel like I'm talking so much nonsense, but it's okay because I'm not tired of typing ~

It is hard to understand or have some simple-single-or-whimsical ideas that won't write code and then @ me.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.