I can't seem to put together a variable

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

I can't seem to put together a variable

Post by Ranguna259 »

So I was trying to do this little love program that saves coordinates to a variable but for some reason it isn't saveing them right.

Basically whenever you press the left mouse button the coordinates of the mouse's current position are saved to pointx pointy[a]

And once there are more than 3 coordinates for both X and Y there is an if code (well, it's a for inside an if) in the love.update(dt) that puts all the coordinates together in one variable called startxy and each coordinate is separated by a comma ",". It does that so that they can be used to draw a line like love.graphics.line(startxy)

This for code is not coded right but I can't seem to see what's wrong with it.

So can somebody please find what's wrong in this code also ignore all the cluster in there, I haven't properly cleaned it yet. :P

Thanks for reading and please help me on this ^^
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: I can't seem to put together a variable

Post by Plu »

You cannot store multiple return values in a single variable unless that variable is a table.

So this:

Code: Select all

a = b, c
effectively just does the same as this:

Code: Select all

a = b
as the second value has nowhere to go.

If you want to add values to a table, you need to put in a few table.insert calls.

Something like this:

Code: Select all

table.insert( startx, pointx[1] )
table.insert( startx, pointy[1] )
should probably help you fix your problems.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: I can't seem to put together a variable

Post by Ranguna259 »

Plu wrote:You cannot store multiple return values in a single variable unless that variable is a table.

So this:

Code: Select all

a = b, c
effectively just does the same as this:

Code: Select all

a = b
as the second value has nowhere to go.

If you want to add values to a table, you need to put in a few table.insert calls.

Something like this:

Code: Select all

table.insert( startx, pointx[1] )
table.insert( startx, pointy[1] )
should probably help you fix your problems.
Yep that did the job, thanks man :awesome:

You can check how it came out.
Once again, thanks :)
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
Post Reply

Who is online

Users browsing this forum: No registered users and 268 guests