Referencing resources through expression

For questions about using Classic.

Post » Mon Apr 09, 2012 11:08 am

I just wanted to ask if there really is no way to reference a resource in your project's "Files" folder other than by its numbered index in the list? With me using a function to play sounds for ease of use and communication with external files, I can't ever change the order of the files in the Files folder without the functions playing the incorrect sounds until I put the list back in the old order.

Basically, if I pick a resource (in any plugin I've tried that accesses them) through "use expression", only a number will work. Writing "gun.wav" (Construct will even convert a choice to a string on its own) will not load the file. Either Construct only remembers the files through index number, or there's a way to write it that wouldn't occur to me?

If it's impossible I guess I'd either deal with it as I have, or make events that plays the sounds I want regardless of list (though that makes for a lot of events), or maybe someone has a better tip? konjak2012-04-09 11:10:29
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

Post » Mon Apr 09, 2012 6:43 pm

The resource filenames are not included when exporting.
You can work around it with this plugin:
http://www.scirra.com/forum/plugin-resource-access_topic39986.html
B
79
S
24
G
54
Posts: 4,754
Reputation: 40,771

Post » Mon Apr 09, 2012 7:34 pm

Oh? How? I was looking at it briefly earlier and didn't find any particular expressions of use, but it again was briefly.

I'll mess with it later then if you don't feel like explaining a lot.
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

Post » Mon Apr 09, 2012 11:39 pm

It's pretty simple. Use the action "extract resource" to assign a name to a resource, you would probably do this at the start of the layout.
[code]+ System: Start of layout
-> Resource: Extract Resource "brick.png" as "img1"
-> Resource: Extract Resource "box.png" as "img2"[/code]

Then you can load the resource with any action that loads from a filename.
[code]
-> Sprite: Load frame from Resource ("img1")
[/code]
B
79
S
24
G
54
Posts: 4,754
Reputation: 40,771

Post » Tue Apr 10, 2012 11:43 am

Ah, thanks. Thought it didn't work at first (using it for sound) but I had to Autoplay from "file".

How does this plugin handle the memory of this though? If I extract all my samples at start, do I double the memory usage somehow? And if this doesn't add potential more memory "stops" as new sounds load to play it'll be dandy.

I guess I'm asking if the plugin just references resources differently or if it literally removes data from the resource folder and stores its own copies.
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

Post » Tue Apr 10, 2012 5:57 pm

Resources are inside the exe. The Resource plugin extracts them from the exe to a temp file and creates a hashtable associating a name with the filename. Try "Set text to Resource("img1")" to see where the file was extracted to.
B
79
S
24
G
54
Posts: 4,754
Reputation: 40,771


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests