First question about general programming

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Strelok
Prole
Posts: 18
Joined: Thu Sep 08, 2011 6:44 pm
Location: Brazil - Amazonas

First question about general programming

Post 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?
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: First question about general programming

Post 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).
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: First question about general programming

Post 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.
User avatar
Strelok
Prole
Posts: 18
Joined: Thu Sep 08, 2011 6:44 pm
Location: Brazil - Amazonas

Re: First question about general programming

Post 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
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: First question about general programming

Post 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.
User avatar
Strelok
Prole
Posts: 18
Joined: Thu Sep 08, 2011 6:44 pm
Location: Brazil - Amazonas

Re: First question about general programming

Post by Strelok »

Oh... I did not thought of it. Anyway, I will leave this part for the final. Thanks for the help, guys.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests