Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

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

$
0
0
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'

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>