Jump to content

Set media based on Variable name


Mzebonga

Recommended Posts

I'm working through a scenario where I have three variables that could affect the cartridge that I'm working on. For argument's sake, let's call them myvar1, myvar2 and myvar3.

 

I'd like to change the image of an item (myitemA) based on the values of all three of the variables so I've created a separate variable (myvarX) that concatenates them and also ensures that they are stored alphabetically (thanks to a function). As far as I can tell, with 4 possible values for each variable, this gives me 20 unique alphabetised combinations.

 

I'm quite happy to make 20 images for each possible combination (it's a simple enough process) but I'm hoping to be able to avoid a long and complex IF statement to manage each combination.

 

Is there a way to effectively say:

 

zitemmyitemA.media = "zmediaitemA_"..var_myvarX

 

I speculatively tried this but wasn't particularly surprised that it didn't work.

 

Does anybody know a shorthand way to achieve what I'm trying to do or am I best doing it the long way?

 

I really appreciate any help you can give.

Link to comment

Instead of following the usual convention of having your media declared at the start of the cartridge, have you tried creating a new media object on demand and setting your item's media property to that?

 

The only worry I have with this approach is how the player app reserves memory for the media object. If the app stores the media file's byte array inside the media object upon instantiation, dynamically creating media objects could turn into a Very Bad IdeaTM. Instead, if the app only reads the media file when it's time to display it to the user (and doesn't store the byte array anywhere else), this would work fine.

Link to comment

Thanks for the thorough response.

 

I think the best plan at this stage is to stay in the shallow end of the pool and work it through as an IF statement. Maybe one day I'll be braver and try to build something a bit more elegant.

 

I really appreciate the feedback, though.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...