LUNAR Lua+Narrative

Show off your games, demos and other (playable) creations.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: LUNAR Lua+Narrative

Post 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!
Attachments
example.love
(671 Bytes) Downloaded 89 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LUNAR Lua+Narrative

Post 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()
Help us help you: attach a .love.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: LUNAR Lua+Narrative

Post 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.
Attachments
LoadingAndSaving.love
Snippet
(496 Bytes) Downloaded 94 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LUNAR Lua+Narrative

Post by Robin »

The definition for the load function should be:

Code: Select all

function load(file)
   return love.filesystem.load(file)()
end
Help us help you: attach a .love.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: LUNAR Lua+Narrative

Post 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.
User avatar
Echo
Prole
Posts: 46
Joined: Fri Jul 13, 2012 4:50 pm
Location: Lucid Moon

Re: LUNAR Lua+Narrative

Post by Echo »

wow I cant thank you guys enough!
(^_^)
User avatar
Echo
Prole
Posts: 46
Joined: Fri Jul 13, 2012 4:50 pm
Location: Lucid Moon

Re: LUNAR Lua+Narrative

Post 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
Attachments
whenever I run the game it tells me this
whenever I run the game it tells me this
error.png (3.64 KiB) Viewed 2367 times
Last edited by Echo on Fri Aug 17, 2012 3:13 pm, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: LUNAR Lua+Narrative

Post by Nixola »

There's a comma at the end of the previous line, it could be the problem
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Echo
Prole
Posts: 46
Joined: Fri Jul 13, 2012 4:50 pm
Location: Lucid Moon

Re: LUNAR Lua+Narrative

Post 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
Attachments
error.png
error.png (3.9 KiB) Viewed 2364 times
Last edited by Echo on Fri Aug 17, 2012 3:31 pm, edited 2 times in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: LUNAR Lua+Narrative

Post by Nixola »

You have to write save_icon.dragging
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests