Page 1 of 1

First question about general programming

Posted: Sun Feb 09, 2014 3:19 am
by Strelok
So, this is my first question and it is about general programming.

Lets say we have this situation: I am making a text based adventure game and it will feature many different places to go with many different options to take. Each place has a big description on it and it would take many lines of code to implement. Lets say that I did not want these descriptions, or the whole places to be within the main.lua, how could I make a .txt or .lua file to store those places, and how could I access it from main.lua?

Do you guys get my doubt?

Re: First question about general programming

Posted: Sun Feb 09, 2014 3:35 am
by Inny
The short answer to your question is that you use the require function to bring in code from an external module. Here's a code sample:

Code: Select all

-- main.lua
local house = require 'house'
local yard = require 'yard'
local street = require 'street'

current_location = street

Code: Select all

-- house.lua
local house = {
  identity = "house",
  description = "Inside the house.",
  exits = {
    south = "yard",
  },
}
return house
For a longer answer, please read the book "Programming In Lua" (free version here).

Re: First question about general programming

Posted: Sun Feb 09, 2014 10:28 am
by micha
Alternatively, you could come up with a new file-type, which saves your game content. The content does not have to be Lua-code. Have a look at map-files. These are not written in Lua, but in an own format. Inside the game, there is a function that can open such files and load them. You can do similar things for "rooms". Have a room-file for each room and inside the game have a function that can load such files.

Re: First question about general programming

Posted: Mon Feb 10, 2014 12:30 am
by Strelok
Hum... got it. So I can have .room files to store my places, and load them with a function in Lua/Löve. That would be good, because a .room file would be of difficult access to players, although I don't think someone would like to modify it. :huh:

Anyway, I have been studying all day long and was able to print my first tilesets and I found it relatively easy. I will try to implement movement and scrolling now. If I do this I will be able to jump from the text game direct to a topdown explorer. :awesome:

And here is what I have learned so far:
http://prntscr.com/2r3jrh

Re: First question about general programming

Posted: Mon Feb 10, 2014 8:16 am
by Plu
Unless you take extra time to write the file in something either binary or hard to read, people will just be able to open your .room file using notepad and read its contents. It's still written as a common string by default.

Re: First question about general programming

Posted: Tue Feb 11, 2014 9:24 pm
by Strelok
Oh... I did not thought of it. Anyway, I will leave this part for the final. Thanks for the help, guys.