Results 1 to 5 of 5

Thread: Help with a simple game's code (LUA)

  
  1. #1
    Gblo6689 is offline -Hacks Newbie
    Join Date
    Nov 2008
    Location
    Tampa, Florida, USA
    Posts
    22
    Rep Power
    0

    Default Help with a simple game's code (LUA)

    okay so I've been trying to figure out how to do this for a little while now and I figure you might be able to help

    I'm trying to make a simple dice game that I and my fiance enjoy playing for the PSP. My problem is that I need the code to recognize if multiple dice have the same value, and if so the player is awarded extra points.

    The awarding of points is easy, however I cannot for the life of me think of an efficient way to tell the program to check if 3 of the 5 dice have the same value...

    for instance:
    if the player rolls 3 sixes he/she gains 600 points
    if the player rolls 3 ones he/she gains 1000 points

    I'm assigning values as such:

    Dice={}
    Dice[1]={RollValue=0}
    Dice[2]={RollValue=0}
    Dice[3]={RollValue=0}
    Dice[4]={RollValue=0}
    Dice[5]={RollValue=0}

    for a=1,5 do
    Dice[a].RollValue=math.random(1,6)
    end

    This is only an exert of the whole code, however, you get the gist.
    I currently have the code recognizing the values of single dice and assigning points according to that.

    Any help would be appreciated.


  2. #2
    Blade_punk's Avatar
    Blade_punk is offline Programmer -Hacks Guru
    Join Date
    Nov 2006
    Location
    Candy Mountain
    Posts
    2,314
    Rep Power
    14

    Default

    ..::Moved to Lua Scripting::..

    -Rock Station-
    PSN: Xsjado7


  3. #3
    Blade_punk's Avatar
    Blade_punk is offline Programmer -Hacks Guru
    Join Date
    Nov 2006
    Location
    Candy Mountain
    Posts
    2,314
    Rep Power
    14

    Default

    Try something like
    Code:
    for i = 1, 5 do
    for j = 1, 5 do
    if(Dice[i].RollValue == Dice[j].RollValue)awardPoints()
    end
    end
    I think thats how it'd be done in Lua (I program in C/C++). You should get the idea though

    -Rock Station-
    PSN: Xsjado7


  4. #4
    HyperHacker's Avatar
    HyperHacker is offline Programmer -Hacks Enthusiast
    Join Date
    Nov 2008
    Location
    Ontario
    Posts
    310
    Rep Power
    10

    Default

    That needs to check that it's not comparing a die to itself.
    Code:
    for i = 1, 5 do
    	for j = 1, 5 do
    		if i ~= j and Dice[i].RollValue == Dice[j].RollValue then awardPoints() end
    	end
    end
    >> PSP-2001 running 5.00m33-6, 4GB Lexar memory stick

  5. #5
    Gblo6689 is offline -Hacks Newbie
    Join Date
    Nov 2008
    Location
    Tampa, Florida, USA
    Posts
    22
    Rep Power
    0

    Default

    Thanks guys, I ended up doing something like that. I got help with it like a minute after I posted here on luaplayer.com (I thought it was a pretty dead forum, but I guess not.)

    Thanks again though

Posting Permissions

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