Can't load images

Hello , everyone.

I’m having a hard time trying to figure out how to load the images on the build for Windows.

I am doing something like this:

object.fill = “here goes the image path”

But get an error, cannot find the image I’m requiring to.

Is this an error related to file management?

Have never had any issues with Windows builds and images. Double-check the filename, because they will be case-sensitive, including the extension and folder names.

I’ll see that in a moment…

It’s happening because of the image being declared in another file module maybe?

I don’t know, we’d need to see some code.

The computer I’m currently using for Corona projects is really far from me so unfortunately can’t do that right now…

But when I reach home, I’ll show you the code.

It’s like this:

local moduleContainer = require("M") local image = display.newRect(rectOptions) image.fill = moduleContainer.path --In moduleContainer.path { type = "image", filename = "path/to/file.png" }

A few questions:

Is there really a file called M.lua in the main project directory? Or is this just example code? 

Also, what is ‘rectOptions’? If it’s a table, that won’t work - the parameters of newRect are not passed inside a table. You’d have to pass rectOptions[1], rectOptions[2] or rectOptions.width, rectOptions.height etc. depending on how the table is structured.

[lua]

– module.lua

local m = {}

  m.path = {type = “image”, filename = “path/to/file.png”}

return m

[/lua]

[lua]

local myModuleHandle = require(“path/to/module”)   – I must be called module.lua and in the folder path/to/

local image = display.newRect(100, 100, 100, 100)

image.fill = myModuleHandle.path

 

[/lua]

If that still doesn’t work, verify you can create an ordinary display.newImageRect using the same image path.

The code I provided was just an example.

But now it’s working!

I replace the part code with the image path to a whole module and now it works.

But really wanted to make it work without requiring a module.

Well I only included the module side as that was what you’re example was doing. Why were you using a module in the first place?

You can get the path string from anywhere - hard-code it, from a variable, from a table, from a variable within another module, from a table within another module, from a variable nested 12 modules down, from a network call, from a text file - it’s up to you. Whatever fits the way you want to build your app. 

I think the reason for this is the high dependency of functions between objects

But thanks anyway!

Have never had any issues with Windows builds and images. Double-check the filename, because they will be case-sensitive, including the extension and folder names.

I’ll see that in a moment…

It’s happening because of the image being declared in another file module maybe?

I don’t know, we’d need to see some code.

The computer I’m currently using for Corona projects is really far from me so unfortunately can’t do that right now…

But when I reach home, I’ll show you the code.

It’s like this:

local moduleContainer = require("M") local image = display.newRect(rectOptions) image.fill = moduleContainer.path --In moduleContainer.path { type = "image", filename = "path/to/file.png" }

A few questions:

Is there really a file called M.lua in the main project directory? Or is this just example code? 

Also, what is ‘rectOptions’? If it’s a table, that won’t work - the parameters of newRect are not passed inside a table. You’d have to pass rectOptions[1], rectOptions[2] or rectOptions.width, rectOptions.height etc. depending on how the table is structured.

[lua]

– module.lua

local m = {}

  m.path = {type = “image”, filename = “path/to/file.png”}

return m

[/lua]

[lua]

local myModuleHandle = require(“path/to/module”)   – I must be called module.lua and in the folder path/to/

local image = display.newRect(100, 100, 100, 100)

image.fill = myModuleHandle.path

 

[/lua]

If that still doesn’t work, verify you can create an ordinary display.newImageRect using the same image path.

The code I provided was just an example.

But now it’s working!

I replace the part code with the image path to a whole module and now it works.

But really wanted to make it work without requiring a module.