i need help with this so i have a script in a folder named "scripts" and i have another folder named "assets"
heres how my game folders work:
so inside the scripts folder the script named "player.lua" and from there im trying to get the assets from the scripts folder in my scripts please help im a newbie
|game/
assets/
images/
myfile.png
scripts/
player.lua
------------
main.lua
how do i get files outside folder?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- NoreoAlles
- Party member
- Posts: 130
- Joined: Mon Jan 03, 2022 5:42 pm
Re: how do i get files outside folder?
you have to put this line on the top of your main.lua, or whatever file should get acces to the player assets:
replace your folder namer with the folder you want to open up a file in or just the filename without folder and slash if your file is in the same folder as your main.lua
In your case propably
Code: Select all
require "yourFolderNameHere/filename.lua
In your case propably
Code: Select all
require "scripts/player.lua"
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
Re: how do i get files outside folder?
Code: Select all
require "scripts.player"
Also from the wiki:It's strongly recommended to use period as directory separator! Forward slashes accidently work, hence its usage is discouraged! One of the reasons is that loading modules that are not Lua code files is only possible with dots as separator, and using dots and slashes at the same time might lead to mixing separators, and due to mixing require might load the same code multiple times.
Here is a snippet of my current project for reference:If the module is a lua file, don't use the .lua extension
Code: Select all
require 'lib.buttons'
require 'enums'
require 'constants'
fun = require 'functions'
cf = require 'lib.commonfunctions'
lists = require 'lib.lists'
animate = require 'lib.animate'
Code: Select all
IMAGE = {}
IMAGE[1] = love.graphics.newImage("assets/images/myfile.png")
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
Re: how do i get files outside folder?
Because it is not a module. `require` is Lua's module manager and that works with periods; `newImage` works with love.filesystem and therefore requires slashes.
Who is online
Users browsing this forum: Ahrefs [Bot] and 6 guests