Page 2 of 4
Re: LUNAR Lua+Narrative
Posted: Sun Aug 12, 2012 2:48 pm
by Santos
I really love the aesthetics of this!
To put variable into tables, you can use
table.insert. For example...
Code: Select all
t = {}
table.insert(t, 'Oh sweet!')
print( t[1] ) --> 'Oh sweet!'
Here's a
post by josefnpat about saving.
Kikito's
love-tile-tutorial has a nice section on Lua, including
tables and
loops, and there's a
tables tutorial on the lua-users wiki too, and I also wrote a
post which has some stuff about tables.
As for mouse dragging, check out
this tutorial.
Here's an example which goes a bit further. Try dragging the green box!
Re: LUNAR Lua+Narrative
Posted: Sun Aug 12, 2012 4:05 pm
by Robin
It might be better to use string keys instead of number keys, in this case.
Code: Select all
local t = {page = page, next_text = next_text, upper_limit = upper_limit, lower_limit = lower_limit}
Then you can serialise
t to a string and save that.
EDIT: also,
Code: Select all
local x, y = love.mouse.getPosition()
is the same as
Code: Select all
local x = love.mouse.getX()
local y = love.mouse.getY()
Re: LUNAR Lua+Narrative
Posted: Sun Aug 12, 2012 5:44 pm
by Roland_Yonaba
Well, you already got nice links.
I'll add a pinch of salt though, about the saving system.
First, do use
love.filesystem.setidentity to set the save folder path (the inside Appdata/love user directory)
Then you can proceed as said before, packing your variables into a regular Lua table.
Code: Select all
function love.load()
love.filesystem.setIdentity('MyGame')
data = {}
data.page = 1
data.next_text = 10
data.upper_limit = 20
data.lower_limit = 0
end
Now, you can use a basic snippet to turn your table into a string:
Code: Select all
function _tostring(data)
local buf = 'return {'
for i,v in pairs(data) do
buf = buf .. i ..' = '..v..','
end
buf = buf .. '}'
return buf
end
Assuming that, saving and loading data is now fairly simple:
Code: Select all
function save(data)
love.filesystem.write('sav',_tostring(data))
end
function load(file)
return loadfile(love.filesystem.getSaveDirectory()..'/'..file)()
end
Loadfile is legible here just because data were previously written in a way it can be parsed by Lua.
See
loadfile,
Lua tables for more details.
That's a very simple example. According o your needs you may want something more improved, or not.
Re: LUNAR Lua+Narrative
Posted: Sun Aug 12, 2012 6:04 pm
by Robin
The definition for the load function should be:
Code: Select all
function load(file)
return love.filesystem.load(file)()
end
Re: LUNAR Lua+Narrative
Posted: Sun Aug 12, 2012 7:02 pm
by Roland_Yonaba
Robin wrote:The definition for the load function should be:
Code: Select all
function load(file)
return love.filesystem.load(file)()
end
Oh right. I still tend to stick to Lua's native IO facilities.
Thanks poiting that out.
Re: LUNAR Lua+Narrative
Posted: Wed Aug 15, 2012 3:38 pm
by Echo
wow I cant thank you guys enough!
(^_^)
Re: LUNAR Lua+Narrative
Posted: Fri Aug 17, 2012 3:08 pm
by Echo
so after some brilliant help and learning I put the drag and drop into action but the code I made
has a problem that does not exist!
Instead drawing a rectangle I used a save_icon image because that is what I want to be dragged.
here is my code
Code: Select all
require 'save'
function love.load
save_icon = {}
save_icon.image = love.graphics.newImage ("interface/theme_notebook/save_icon.png"),
--drag drop variables
save_icon.x = (665) --THIS IS LINE 30 but there should be NO PROBLEM!?
save_icon.y = (230)
save_icon.width = (32)
dragging = {active = false , diffX = 0 , diffY = 0}
end
here is 'save' it is just like the drag and drop example but I made sure it used the save_icon instead of a rectangle
Code: Select all
function love.mousepressed(x,y,button)
if ( button == "l" )
and x > save_icon.x and x < save_icon.x + save_icon.width
and y > save_icon.y and y < save_icon.y + save_icon.height
then
save_icon.dragging.active = true
save_icon.dragging.diffX = x - save_icon.x
save_icon.dragging.diffY = y - save_icon.y
end
end
function love.update(dt)
if ( save_icon.dragging.active == true ) then
save_icon.x = ( love.mouse.getX() - save_icon.dragging.diffX )
save_icon.y = ( love.mouse.getY() - save_icon.dragging.diffY )
end
end
function love.mousereleased(x, y, button)
if ( button == "l" )then
save_icon.dragging.active = false
end
end
Re: LUNAR Lua+Narrative
Posted: Fri Aug 17, 2012 3:12 pm
by Nixola
There's a comma at the end of the previous line, it could be the problem
Re: LUNAR Lua+Narrative
Posted: Fri Aug 17, 2012 3:20 pm
by Echo
Yeah (0_0) I would have never seen it.
Thanks
But now It cant recognize that dragging is a table. I followed the drag drop tutorial and this is how they declared dragging as a table
Code: Select all
dragging = {active = false , diffX = 0 , diffY = 0}
Why then does it not work for me? In the example.love this is exactly how it was used...
do I have to write as...
Code: Select all
save_icon.dragging = {active = false , diffX = 0 , diffY = 0}
which is what I thought before I looked at the drag drop tutorials dragging table.
here is "save" again
Code: Select all
function love.mousepressed(x,y,button)
if ( button == "l" )
and x > save_icon.x and x < save_icon.x + save_icon.width
and y > save_icon.y and y < save_icon.y + save_icon.height
then
save_icon.dragging.active = true
save_icon.dragging.diffX = x - save_icon.x
save_icon.dragging.diffY = y - save_icon.y
end
end
function love.update(dt)
if ( save_icon.dragging.active == true ) then --THIS IS LINE 13
save_icon.x = ( love.mouse.getX() - save_icon.dragging.diffX )
save_icon.y = ( love.mouse.getY() - save_icon.dragging.diffY )
end
end
function love.mousereleased(x, y, button)
if ( button == "l" )then
save_icon.dragging.active = false
end
end
Re: LUNAR Lua+Narrative
Posted: Fri Aug 17, 2012 3:26 pm
by Nixola
You have to write save_icon.dragging