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?
First question about general programming
Re: First question about general programming
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:
For a longer answer, please read the book "Programming In Lua" (free version here).
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
Re: First question about general programming
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.
Check out my blog on gamedev
Re: First question about general programming
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.
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.
And here is what I have learned so far:
http://prntscr.com/2r3jrh
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.
And here is what I have learned so far:
http://prntscr.com/2r3jrh
Re: First question about general programming
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
Oh... I did not thought of it. Anyway, I will leave this part for the final. Thanks for the help, guys.
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests