Concating strings and integers

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MichaelShort
Prole
Posts: 14
Joined: Mon Sep 28, 2015 3:28 pm

Concating strings and integers

Post by MichaelShort »

So we're trying to concat log and i. When that happens we will be able to identify the log by its log number. ex log256 and log320
log..i doesn't concat it so any help would be appreciated. We're new to love2d.

Code: Select all

for i=64, 1856, 192 do
	love.graphics:reset()
    	logs = { log..i = love.graphics.draw(logImg, i, 896) }
end
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Concating strings and integers

Post by micha »

Concatenating string does not work implicitely in table definitions. Try this instead:

Code: Select all

logs = {}
for i=64, 1856, 192 do
  local key = log..i
  logs[key] = whatever
end
But I am not sure what you try to achieve by assigning the return value of love.graphics.draw to a variable. love.graphics.draw does not return anything.

Furthermore, it is probably much better to use the number i as key directly instead of turning it into a string:

Code: Select all

logs = {}
for i=64, 1856, 192 do
  logs[i] = whatever
end
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Concating strings and integers

Post by bartbes »

The correct syntax here is

Code: Select all

for i=64, 1856, 192 do
    love.graphics:reset()
    logs = {["log" .. i] = love.graphics.draw(logImg, i, 896)}
end
Sadly, semantically this isn't what you want at all. I doubt you want to reset the graphics every iteration (and it's love.graphics.reset, not love.graphics:reset), nor would you want to recreate the 'logs' table every iteration. And, of course, as micha said, love.graphics.draw doesn't return anything, and you'd probably just want the keys to be numbers anyway.
MichaelShort
Prole
Posts: 14
Joined: Mon Sep 28, 2015 3:28 pm

Re: Concating strings and integers

Post by MichaelShort »

Alright thank you guys.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests