Having trouble coding a point and click coding

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
SuperScourge
Prole
Posts: 14
Joined: Tue Apr 16, 2013 8:38 am

Having trouble coding a point and click coding

Post by SuperScourge »

I'm building a test Beta Demo of my Seek & Destory Engine that has similar functions to Command and Conquer Red Alert's Engine, I'm not sure if it's

Code: Select all

love.mouse.isdown 
or something else to click once on an object like a circle and then click again to move it the spot where it was clicked to like for exmaple it moves to area 120, 40 and stops at the clicked point. this is fromMunkeeBacon's tutorial from youtube to use a key to move the cicle when I've done it with the mouse.isdown code it just gives no circle just a blank screen.

here's the Code I followed from him to make with my own mod to use the mouse clicks not from pressing a key like Left Arrow key

Code: Select all


player = {}

function player.load()
    player.x = 5
    player.y = 5
    player.xvel = 0
    player.yvel = 0
    player.friction = 7
    player.speed = 2300
    player.width 50
    player.height 50
end
function player.draw()
     love.graphics.setcolor (150,255,0)
     love.graphics.rectangle("fill", player.x, player.y,player.width,player.height)
end

function player.physics(dt)
   player.x = player.x + player.xvel = dt
   player.y = player.y + player.yvel = dt
   player.xvel = player.xvel = (1 = math.min(dt*player.friction, 1))
end

function update_player(dt)
player.physics(dt)

end

function draw_player()
player.draw
end

function player.move(dt)
if love.mouse.isdown ("l") and
player.xvel < player.speed then
player.xvel = player.xvel + player.speed + dt
end
if love.mouse.isdown("l") then
player.xvel > -player.xvel - player.speed + dt

end
not sure why I'm getting a blank screen is there something missing from the Main.lua file?

Code: Select all

--[[You may modify the game's files as long you do it under the 

the share license to share-alike and the other stuff within the license now have fun using my game's code
as long you don't mess it around too much!]]

function love.load()

end		


--Required Lua Files Here--
- empty as is.
Attachments
Seek & Destory Engine Demo.love
(2.22 KiB) Downloaded 119 times
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Having trouble coding a point and click coding

Post by micha »

You need to "require" the file Sprite.lua. Otherwise LÖVE does not read or run its content.
User avatar
SuperScourge
Prole
Posts: 14
Joined: Tue Apr 16, 2013 8:38 am

Re: Having trouble coding a point and click coding

Post by SuperScourge »

micha wrote:You need to "require" the file Sprite.lua. Otherwise LÖVE does not read or run its content.
Added in now within' the test Sprite it now says this error

Error

Synatx Error Sprite.lua:21: unexpected symbol near '='

Trackback
[C]: ?
[C]: in function 'require'
main.lua:19:in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'

I'm sure I'm doing it all wrong the circle sprite was from the tutorial I've followed to render a circle but under my mouse clicks
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Having trouble coding a point and click coding

Post by micha »

Indeed, your code has some errors in it.

Code: Select all

player.xvel = player.xvel = (1 = math.min(dt*player.friction, 1))
should be replaced by this probably:

Code: Select all

player.xvel = player.xvel - (1 - math.min(dt*player.friction, 1))
Also in the function player.move you need to add one more "end". I suggest you indent your code properly, then such errors become more visible.
User avatar
SuperScourge
Prole
Posts: 14
Joined: Tue Apr 16, 2013 8:38 am

Re: Having trouble coding a point and click coding

Post by SuperScourge »

micha wrote:Indeed, your code has some errors in it.

Code: Select all

player.xvel = player.xvel = (1 = math.min(dt*player.friction, 1))
should be replaced by this probably:

Code: Select all

player.xvel = player.xvel - (1 - math.min(dt*player.friction, 1))
Also in the function player.move you need to add one more "end". I suggest you indent your code properly, then such errors become more visible.
I've fixed it up and still have an error I'll just look at the mouse section so I can rewrite this this was from a tutorial from youtube meant for keydown one.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 53 guests