Having trouble getting a program running

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
adrywalsh
Prole
Posts: 20
Joined: Fri Feb 26, 2010 7:24 am

Having trouble getting a program running

Post by adrywalsh »

I'm trying to write a program that simulates a 7 card hand dealt randomly, and putting output to the console if the hand was good or bad, but I'm not getting anywhere at all.
What is wrong?
I'm not getting an error, just a blank console.

Code: Select all

function love.main()
	while total < 100 do
		while rand[1] == rand[2]
		
			do
			rand[1] = math.random(60)
			rand[2] = math.random(60)
			rand[3] = math.random(60)
			rand[4] = math.random(60)
			rand[5] = math.random(60)
			rand[6] = math.random(60)
			rand[7] = math.random(60)
			end
		if Deck[rand[1]] == 'A' or 'B' or 'C' or 'D' then
			points = points + 1
		end
		if Deck[rand[2]] == 'A' or 'B' or 'C' or 'D' then
			points = points + 1
		end
		if Deck[rand[3]] == 'A' or 'B' or 'C' or 'D' then
			points = points + 1
		end
		if Deck[rand[4]] == 'A' or 'B' or 'C' or 'D' then
			points = points + 1
		end
		if Deck[rand[5]] == 'A' or 'B' or 'C' or 'D' then
			points = points + 1
		end
		if Deck[rand[6]] == 'A' or 'B' or 'C' or 'D' then
			points = points + 1
		end
		if Deck[rand[7]] == 'A' or 'B' or 'C' or 'D' then
			points = points + 1
		end
		if points > 2 then
			for x = 1, 7, 1 do
				hand[x] = Deck[rand[x]]
			end
			for a = 1, 7, 1 do
				if hand[a] == 'A' then
					thereisana = true
				end
				if hand[a] == 'B' then
					thereisab = true
				end
				if hand[a] == 'C' then
					thereisac = true
				end
				if hand[a] == 'D' then
					thereisad = true
				end
			end
			if (thereisana and thereisab and thereisac) or (thereisad and thereisab and thereisac) or (thereisana and thereisad and thereisac) or (thereisana and thereisab and thereisad) then
				wins = wins + 1
			else
				fail = fail + 1
			end
		end
	total = total + 1
	rand[1] = 0
	rand[2] = 0
	rand[3] = 0
	rand[4] = 0
	rand[5] = 0
	rand[6] = 0
	rand[7] = 0
	thereisana = false
	thereisab = false
	thereisac = false
	thereisad = false
	a = 0
	x = 0
	points = 0
	print(wins)
	print(total)
	print(wins/total*100)
	print(hand[1])
	print(rand[1])
	end
end
function love.load()
math.randomseed(os.time()) 
math.random()
math.random()
math.random()
thereisana = false
thereisab = false
thereisac = false
thereisad = false
points = 0
rand = {}
	rand[1] = 0
	rand[2] = 0
	rand[3] = 0
	rand[4] = 0
	rand[5] = 0
	rand[6] = 0
	rand[7] = 0
wins = 0
fail = 0
total = 0
hand = {}
Deck = {}
	Deck[20] = 'A'
	Deck[40] = 'A'
	Deck[60] = 'A'
	Deck[9] = 'B'
	Deck[17] = 'B'
	Deck[25] = 'B'
	Deck[33] = 'B'
	Deck[39] = 'B'
	Deck[49] = 'B'
	Deck[56] = 'B'
	Deck[11] = 'C'
	Deck[23] = 'C'
	Deck[35] = 'C'
	Deck[47] = 'C'
	Deck[59] = 'C'
	Deck[5] = 'D'
	Deck[12] = 'D'
	Deck[19] = 'D'
	Deck[26] = 'D'
	Deck[34] = 'D'
	Deck[39] = 'D'
	Deck[48] = 'D'
	Deck[55] = 'D'
end
function love.draw()
end
while (1)
do LÖVE
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Having trouble getting a program running

Post by bartbes »

Well, ehm.. love.draw is empty...
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Having trouble getting a program running

Post by nevon »

You never actually run love.main()
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: Having trouble getting a program running

Post by Luiji »

Yeah, [love.main()] is a not a standard function to override. 404!
Good bye.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Having trouble getting a program running

Post by Jasoco »

Instead of love.main, you need to use love.load. Put stuff you need to setup in load, stuff to calculate in update and stuff you want to draw in draw. You can also make a custom love.run if you want to. (I did. It's really nice to be able to customize that part.)
User avatar
adrywalsh
Prole
Posts: 20
Joined: Fri Feb 26, 2010 7:24 am

Re: Having trouble getting a program running

Post by adrywalsh »

Resolved.

I changed "main" to "update"

Cookies for all!
while (1)
do LÖVE
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: Having trouble getting a program running

Post by Luiji »

Cookies would be good right now. :P

On a completely unrelated note in an unconstructive post: why do all of the LÖVE smileys have ears?
Good bye.
User avatar
adrywalsh
Prole
Posts: 20
Joined: Fri Feb 26, 2010 7:24 am

Re: Having trouble getting a program running

Post by adrywalsh »

How about an easy way to make sure all elements in an array are unequal?

Cookies in the oven.
while (1)
do LÖVE
User avatar
adrywalsh
Prole
Posts: 20
Joined: Fri Feb 26, 2010 7:24 am

Re: Having trouble getting a program running

Post by adrywalsh »

I'm thinking nested for loops that check every term against every term?
A little wasteful if done poorly, but should work.

Guess i'll eat those cookies mahself!
while (1)
do LÖVE
User avatar
Luiji
Party member
Posts: 396
Joined: Mon May 17, 2010 6:59 pm

Re: Having trouble getting a program running

Post by Luiji »

That's the only way I know to check. Inefficient, yes, but collision systems do such loops to find collisions and they function.
Good bye.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests