4 Replies - 2014 Views - Last Post: 20 February 2013 - 02:23 PM Rate Topic: -----

#1 LongcatX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-January 13

Love2D, Lua, No clue whats wrong with my game's code!

Posted 28 January 2013 - 04:38 PM

okay so i have been trying to create a simple turn based combat system for use in a,hopefully , larger project. Mainly what i have been having issues with is adding the AI system to the game.
code here:
 -- setting values
p1hp=1000 
e1hp=1000
atkdmg=200
blockdmg=200
atkeng=5
blockeng=20
p1eng=200
e1eng=200
engbld=400
defeat=0
victory=0
AI=1




function love.load()
	PICTURE = love.graphics.newImage( "/textures/herpies.png" )	
end 

function love.draw() --drawing interface
	love.graphics.print( "Player Health " ..  p1hp, 5, 30)
	love.graphics.print("Player Energy " ..  p1eng, 305, 30)
	love.graphics.print("Enemy Health " .. e1hp, 5, 230 )
	love.graphics.print("Enemy Energy " .. e1eng, 305, 230 )
	love.graphics.draw (PICTURE, 300, 300, 0, 1, 1, 0, 0 )
	
	
end

function love.update(dt)
	
	end
	
	
	
	
	
 


function love.focus(bool)
	
	
end

function love.keypressed( key, unicode )
	if key == "a" then --player attacks
		e1hp=e1hp-atkdmg
		p1eng=p1eng-atkeng
			
			
						--decides the AI's move
			
			if AI=1 then
				p1hp=p1hp-atkdmg
				e1eng=e1eng-atkeng
				AI=AI + 1
					
			if AI=3 then
				p1hp=p1hp-atkdmg
				e1eng=e1eng-atkeng
				AI=AI+ 1
				
			if AI=5 then
				e1hp=e1hp+blockdmg
				e1eng=e1eng-blockeng
				AI=AI +1
				
			if AI=6 then
				AI = 1
			
			
			
			
			
			if p1eng<1 then --checks player's energy
				p1hp=0
				p1eng=0
				atkdmg=0
				defeat=1
			
			if p1hp<1 then --checks player's health
				p1hp=0
				p1eng=0
				atkdmg=0
				defeat=1
				
			if e1hp<1 then
				e1hp=0
				e1eng=0
				atkdmg=0
				victory=1
			if e1eng<1 then
				e1hp=0
				e1eng=0
				atkdmg=0
				victory=1
				end
				end
			
				end
				end
				end
				end
			end
		end
	end


	
	if key == "h" then --player heals
		p1hp=p1hp+blockdmg
		p1eng=p1eng-blockeng
			if p1eng<1 then --checks players energy
				p1hp=0
				p1eng=0
				atkdmg=0
			if p1hp<1 then --checks players health
				p1hp=0
				p1eng=0
				atkdmg=0
				if e1hp<1 then
				e1hp=0
				e1eng=0
				atkdmg=0
				victory=1
			if e1eng<1then
				e1hp=0
				e1eng=0
				atkdmg=0
				victory=1
				end
				end
			end
				
				
			
				
				
			
			end
		end
	end


function love.keyreleased( key, unicode )
	
end

function love.mousepressed( x, y, button )
	
end

function love.mousereleased( x, y, button )
end

function love.quit()
end
     

i have tried rearranging the end commands spacing the "if" commands and just generally moving things about. I have also tried using a random number generator to decide the AI's choice; alas that has failed and i shall post my work here in hopes of getting some clarity on the situation.

anyways heres the error i get when i try to start it:

Error

Syntax error: main.lua:56: 'then' expected near '='


Tracebakc

[C]:?
[C]:in function 'require'
[C]:in function 'xpcall'

Is This A Good Question/Topic? 0
  • +

Replies To: Love2D, Lua, No clue whats wrong with my game's code!

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5625
  • View blog
  • Posts: 12,061
  • Joined: 02-June 10

Re: Love2D, Lua, No clue whats wrong with my game's code!

Posted 28 January 2013 - 05:49 PM

I know nothing of this language but I can spot inconsistancies.

In this use of if you have a double equal sign like in C/C# langauges
049 if key == "a"

But below you use a single as if in VB.NET. In a C like language this would be an assignment not a comparison. x = 4

056 if AI=1 then

This post has been edited by tlhIn`toq: 28 January 2013 - 05:50 PM

Was This Post Helpful? 1
  • +
  • -

#3 LongcatX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-January 13

Re: Love2D, Lua, No clue whats wrong with my game's code!

Posted 28 January 2013 - 07:20 PM

Thanks, now i have somthing else to try at least!
Was This Post Helpful? 0
  • +
  • -

#4 LongcatX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-January 13

Re: Love2D, Lua, No clue whats wrong with my game's code!

Posted 20 February 2013 - 02:21 PM

#bumpcauseistillhaventfigureditout
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,767
  • Joined: 12-June 08

Re: Love2D, Lua, No clue whats wrong with my game's code!

Posted 20 February 2013 - 02:23 PM

What's the current error list and code? It's been a month and I assume there's been some sort of movement on both.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1