Results 1 to 4 of 4

Thread: beginners codes LUA for cards

  1. #1

    Question beginners codes LUA for cards


    I am trying to program a simple code on a deck of cards but since I'm new to coding, I don't get the result I want.

    What do i want :
    I have two decks of cards. Both have to be shuffled onload. This is easy.
    Now I want onload that from deck1, it takes the first card and puts it on a specific place.
    From deck 2, i want the first 5 cards to be put on a specific place (one next to the other).

    I'm sure this is quite simple but I don't succeed and the tutorials seem to try to learn me to do a hundred other things, but not this.

    So far I have :

    object1_GUID = '211dca' > ok i get it i have to specify my object
    function onload() > to get this done at the beginning of the game
    object1 = getObjectFromGUID(object1_GUID) > I'm sorry I have no clue what this does or if it is necessary
    object1.setName('deck1') > to give it a name, not sure if necessary
    self.shuffle() > so proud i got this to shuffle
    self.flip() > so proud i got this to flip

    This shouldn't be the end. I would like a command that looks like this :
    ..... Place 1 card from deck1 to position (x,y,z)
    .... Place 1 card from deck 2 to position (X, Y, Z)
    .... Place 1 card from deck 2 to position (X+5, Y, Z)
    ... Place 1 card from deck 2 to position (X+10, Y, Z)
    .... Place 1 card from deck 2 to position (X+15, Y, Z)
    ... Place 1 card from deck 2 to position (X+20, Y, Z)
    I'm inventing these commands right now, I really would love to learn how to do this correctly in Lua.

    Thank you for guiding me the right way.

  2. #2
    object1.takeObject({ top=true, position={x, y, z} })
    for i=1,5,1 do
        object2.takeObject({ top=true, position={X+(i-1)*5, Y, Z} })
    First snippet for the first deck, second for second. You can learn about parameters for takeObject from the API page, but in short - top (true/false) means if you want to take from top or bottom of the deck, position is the destination position. For loops works like "from A to B (inclusive), stepping A by increments of C" in the "for A,B,C do (...) end" notation

    Feel free to ask if anything wasn't clear. If something errors out let me know, I was writing off the top of my head.

  3. #3
    K, I just noticed you are pasting each script directly on the decks? That's a good approach and will actually make it simplier. In that case, you don't need to use 'object1' or 'object1_GUID' at all. You would if these scripts were in Global (let me know if you want it that way), but here you can just use 'self' in each object script.
    So it would be:
    function onLoad()
        self.takeObject({ top=true, position={10, 10, 10} })
    on the first deck (that you want to take 1 card off), and I'll let you figure out the script to be pasted on the second deck (hint: 'for' loop for taking cards)

    In particular: When using a script pasted on an object, 'self' represents this object. So you just operate on that. In the Global script, 'self' has no meaning and to reference an object, you have to (for example) write down its GUID, use something like 'myObject = getObjectFromGUID(myObjectGUID)', and then do 'myObject.shuffle() myObject.takeObject(...)' and so on.

    Still, trying different things and then deciphering the errors that are thrown at you (and e.g. asking here if stuck) is the best way to learn. Keep it up

  4. #4
    Thank you so much, I got the cards to do what i want :-)
    I got a little carried away, this is the result and i'm a little proud :-)

    object1_GUID = 'f161c0'
    object2_GUID = '4ec42f'
    object3_GUID = 'f4dbe2'
    object4_GUID = '1d38f9'
    object5_GUID = 'e27e76'
    object6_GUID = '6908b8'
    object7_GUID = 'bc7315'
    object8_GUID = '9b23df'
    object9_GUID = 'fc0edc'
    object10_GUID = '6302c1'

    a1 = {7, 4.23,-21}
    a2 = {3.5, 4.23,-21}
    a3 = {0, 4.23,-21}
    a4 = {-3.5,4.23,-21}
    a5 = {-7,4.23,-21}

    v1 = {21 ,4,-19.64}
    v2 = {17,4,-19.64}
    v3 = {14,4,-19.64}
    v4 = {10,4,-19.64}
    v5 = {-10,4,-19.64}
    v6 = {-14,5,-19.64}
    v7 = {-17,4,-19.64}
    v8 = {-21,4,-19.64}

    function onLoad()

    deckvillains = getObjectFromGUID(object1_GUID)
    henchmen1 = getObjectFromGUID(object2_GUID)
    henchmen2 = getObjectFromGUID(object3_GUID)
    henchmen3 = getObjectFromGUID(object4_GUID)
    henchmen4 = getObjectFromGUID(object5_GUID)
    henchmen5 = getObjectFromGUID(object6_GUID)
    henchmen6 = getObjectFromGUID(object7_GUID)
    henchmen7 = getObjectFromGUID(object8_GUID)
    henchmen8 = getObjectFromGUID(object9_GUID)
    portal = getObjectFromGUID(object10_GUID)

    label="setup", click_function="setup",
    function_owner=self, position={0,0,2},
    height=500, width=1000, font_size=100

    function setup(entity, color)

    deckvillains.takeObject({ top=true, position=a1 })
    deckvillains.takeObject({ top=true, position=a2 })
    deckvillains.takeObject({ top=true, position=a3 })
    deckvillains.takeObject({ top=true, position=a4 })
    deckvillains.takeObject({ top=true, position=a5 })

    henchmen1.takeObject({ top=true, position=v1 })

    henchmen2.takeObject({ top=true, position=v2 })

    henchmen3.takeObject({ top=true, position=v3 })

    henchmen4.takeObject({ top=true, position=v4 })

    henchmen5.takeObject({ top=true, position=v5 })

    henchmen6.takeObject({ top=true, position=v6 })

    henchmen7.takeObject({ top=true, position=v7 })

    henchmen8.takeObject({ top=true, position=v8 })


    print 'now choose your 5 heroes'


Similar Threads

  1. Replies: 1
    Last Post: 02-18-2017, 02:14 PM
  2. Cards being duplicerad when shuffling cards in hand(!)
    By FurbyFubar in forum Bug Reports
    Replies: 3
    Last Post: 09-25-2016, 04:38 PM
  3. [ADDED] [v7.9] Add Hex Codes to the Color Tint system
    By TheRaven81 in forum Suggestions
    Replies: 4
    Last Post: 09-17-2016, 02:41 PM
  4. Replies: 0
    Last Post: 04-05-2016, 01:31 PM
  5. [ADDED] High resolution cards (built from decks not required to be 10x7 cards)
    By SwiftIllusion in forum Suggestions
    Replies: 11
    Last Post: 12-22-2015, 01:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts