[SOLVED]Require all files in a folder
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [SOLVED]Require all files in a folder
Do you need any help, or are you just reporting your findings ? If you get stuck, give me the exact folder structure and I will try to give you the code that you need.
When I write def I mean function.
Re: [SOLVED]Require all files in a folder
Hi kikito!
Well, my gamedir is benGame and i have an /entities off that. Do you need the entire path? c:\games\benGame\entities.
Thanks for the help!
Well, my gamedir is benGame and i have an /entities off that. Do you need the entire path? c:\games\benGame\entities.
Thanks for the help!
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [SOLVED]Require all files in a folder
The steps would be:
1. Put `require.lua` inside the benGame directory
2. Write this wherever you need the files (for example, in main.lua)
The returned entities table should be a table with 1 entry per file and subfolder inside the `benGame/entities` folder. For example, if you have `benGame/entities/player.lua`, there should be a entities.player entry on that table, containing whatever player.lua returns.
1. Put `require.lua` inside the benGame directory
2. Write this wherever you need the files (for example, in main.lua)
Code: Select all
require 'require'
local entities = require.tree('entities')
When I write def I mean function.
Re: [SOLVED]Require all files in a folder
Thanks kikito!
Re: [SOLVED]Require all files in a folder
Hey kikito, I know this is a very old thread, but, I'm having troubles with requiring. My directory is: BeaverBallRevenge/entities/beaver.lua and BeaverBallRevenge/entities/redneck.luakikito wrote:Snip
Code: Select all
local entities = require.tree("entities")
entities.beaver
entities.redneck
...Aidan\Desktop\Programming\Lua\BeaverBallRevenge\main.lua:8: '=' expected near 'entities'
(entities.redneck is line 8)
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [SOLVED]Require all files in a folder
The problem is that "entities.beaver" (or "entities.redneck"), by itself, is not a valid Lua instruction.
You can't put the name of an entity in a line in Lua all by itself. That has no meaning in Lua. You must do something with your entities. For example, drawing them. Or creating instances of them. Something.
Code: Select all
local entities = require.tree("entities")
entities.beaver -- <=== Remove these two lines
entities.redneck -- <=== They are the ones provoking an error
When I write def I mean function.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests