Identifing a audio.loadSound variable!

Hey,

I need to do a verify like we do this in ActionScript 3.0:

if (audioFile is Sound)

althought Lua isnt a strongtype language so I cant do some like:

audioFile = audio.loadSound(“sound/br_curupira.mp3”)

if(audioFile == audio ) then

Someone has any idea?

if(audioFile ?? ??? ) then
Tankyou,
Rafael [import]uid: 88034 topic_id: 20370 reply_id: 320370[/import]

You could create a table and do something like this

[lua]local audioFile = {};

audioFile.handle = audio.loadSound(“sound/br_curupira.mp3”)
audioFile.type = “audio”;

if (audioFile.type == “audio”) then
– do something
end[/lua]
[import]uid: 70847 topic_id: 20370 reply_id: 79594[/import]

Hi @rapadovani,

This may work for you also as will ingemar’s solution…

[code]
local audioFile = nil;
local audio_1 = nil;
audioFile = audio.loadSound(“expl_ogg.ogg”) – or whatever sound format you use

– more simple is just check for nil
– like: if(audiofile == nil) then …etc…
– can’t use the word audio because reserved for corona API
if(audioFile == audio_1 ) then

– sound file not found / loaded
print(“Audio Not Loaded!..”, audioFile);

else

– audioFile will return a handle to the sound file Will show up as: userdata: #########
– where userdata is just a memory placement and ####### is where in memory it’s at (or pointer)
– which by the by will always be greater than nil which equals 0 more or less
– hope this helps…:wink:
print(“Audio Found and Loaded!..”, audioFile);

end
[import]uid: 107633 topic_id: 20370 reply_id: 79708[/import]

Ty, ingemar.

This was something I was looking for to, how to make a object, then to apply more info in each variable. Yes table is the answer.

And this is the sintaxe I was looking for too: local audioFile = {};

Ty again man. [import]uid: 88034 topic_id: 20370 reply_id: 79714[/import]

Tankyou sharp,

This wasnt so elegant althought is another valid answer.

If we could test if some variable == userdata will be perfect. But this wil make things work to me.

Ty man. [import]uid: 88034 topic_id: 20370 reply_id: 79716[/import]