Help me please, I'm noob :S

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Byakko
Prole
Posts: 3
Joined: Thu Jan 29, 2015 4:54 am

Help me please, I'm noob :S

Post by Byakko »

I made a square that you can move with the arrows. When it goes out of the screen it's supposed to appear in the other side. It doesn't work when it goes out from the left or up edge. What am I doing wrong? Here's the code:

Code: Select all

x = 350 
y = 250

function love.load()
	love.graphics.setBackgroundColor( 255, 255, 255, 255)
end

function love.draw()
		love.graphics.setColor( 0, 0, 0, 255 )
	love.graphics.rectangle( "fill", x, y, 100, 100)
end

function love.update(dt)
	if love.keyboard.isDown("right") then
    	x = x + 128*dt
    end

    if love.keyboard.isDown("left") then
    	x = x - 128*dt
    end

    if love.keyboard.isDown("up") then
    	y = y - 128*dt
    end

    if love.keyboard.isDown("down") then
    	y = y + 128*dt
    end

    if x > 800 then
    	x = -100
    end

    if y > 600 then
    	y = -100
    end

    if x = -100 then 
    	x = 900
    end

    if y = -100 then
    	y = 700
    end
end
User avatar
DaedalusYoung
Party member
Posts: 413
Joined: Sun Jul 14, 2013 8:04 pm

Re: Help me please, I'm noob :S

Post by DaedalusYoung »

This:
Byakko wrote:

Code: Select all

    if x = -100 then 
    	x = 900
    end

    if y = -100 then
    	y = 700
    end
is checking if the square is at exactly -100. This probably never happens. Change it to:

Code: Select all

    if x < -100 then 
    	x = 900
    end

    if y < -100 then
    	y = 700
    end
Byakko
Prole
Posts: 3
Joined: Thu Jan 29, 2015 4:54 am

Re: Help me please, I'm noob :S

Post by Byakko »

Oh, that's what I did first and it also didn't work :s
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Help me please, I'm noob :S

Post by s-ol »

Byakko wrote:Oh, that's what I did first and it also didn't work :s
Then maybe use 0 instead of -100? This should definitely work.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Byakko
Prole
Posts: 3
Joined: Thu Jan 29, 2015 4:54 am

Re: Help me please, I'm noob :S

Post by Byakko »

S0lll0s wrote:Then maybe use 0 instead of -100? This should definitely work.
Never mind.

I realized what it's the problem!

Code: Select all

if x > 800 then
    	x = -100
    end

    if y > 600 then
    	y = -100
    end

    if x < -100 then 
    	x = 900
    end

    if y < -100 then
    	y = 700
    end
When x < -100 then it becomes 900, then x > 800 so it's supposed to become -100. I think this makes the program get crazy. I feel stupid
User avatar
pactace
Prole
Posts: 38
Joined: Fri Jan 30, 2015 1:25 am

Re: Help me please, I'm noob :S

Post by pactace »

haha im on the same level with ya bro can anyone give me some code to import enemys I'm doing a 2D platformer and Im so confused :P
Very new programmer dont judge
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: Help me please, I'm noob :S

Post by Doctory »

start another thread @pactace
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Help me please, I'm noob :S

Post by s-ol »

pactace wrote:haha im on the same level with ya bro can anyone give me some code to import enemys I'm doing a 2D platformer and Im so confused :P
that's not an actual question....
Doctory wrote:start another thread @pactace
when he finds a question. For now you better look around the wiki and forum, or open up some other love game. We don't need more threads like "help me: how do I do everything?"

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
pactace
Prole
Posts: 38
Joined: Fri Jan 30, 2015 1:25 am

Re: Help me please, I'm noob :S

Post by pactace »

Really I posted a thread with basically the same title and you guys were mad at me
Very new programmer dont judge
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Help me please, I'm noob :S

Post by Positive07 »

pactace wrote:Really I posted a thread with basically the same title and you guys were mad at me
Yeah... so?

Your post was the main problem, you had no idea what you wanted to do, you had no idea on how to do anything so basically you wanted us to give you everything, and after that you would have asked us to assemble it... that is a BIG NO!

Read, learn, understand and come with a question like this guy did, the title is less important than the question itself. Of course if your post has a title like this then less people will look at it, so a good title is better.

First get your question as Solllos suggested

EDIT: Dont comment dead or already answered threads with this kind of issues... Or I'll start to report your comments.

Also dont "flag" useful threads with comments, that is no good and makes old post pop up as new, which is something no one wants, already answered and solved problems should be left there
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests