Jump to content

Changing Message Images

Followers 2

Recommended Posts

I am building a Wherigo where a player has to fight various monsters. I am trying to create a message that changes image depending upon which monster has been loaded. Is it possible to save an image as a variable? I am trying to avoid creating duplicate message boxes for each monster and this seemed like the easiest way to do so, but my code does not work (I get the text box, but the image does not display). I tried the following example using the string Var_Monster_Image, and I have an Onstart event that set the media for the Var_Monster_Image:



Wherigo.MessageBox{Text="The monster attacks! " , Media=Var_Monster_Image}


If someone knows of a different way to do this, any help would be greatly appreciated. 

Link to comment

Hi Forest-Ghost, sorry for being late.


Here is how I do it in one of my cartridges (I only show relevant excerpts). I hope it makes sense.


-- [...] ---

zmediaMessageImage = Wherigo.ZMedia(cartMyCartridge)
zmediaMessageImage.Id = "97a143a50038652156531ed3a7bd39d5"
zmediaMessageImage.Name = "Placeholder"
zmediaMessageImage.AltText = ""
zmediaMessageImage.Resources = {

zmediaMonsterImage = Wherigo.ZMedia(cartMyCartridge)
zmediaMonsterImage.Id = "a3566d811179a54b0dcf86053f282e32"
zmediaMonsterImage.Name = "Monster"
zmediaMonsterImage.AltText = ""
zmediaMonsterImage.Resources = {
   { Type = "jpg", Filename = "Monster.jpg", Directives = {},}

-- [...] --

function myMsgBox (wzmImage)
   Wherigo.MessageBox{Text="The monster attacks!", Media=zmediaMessageImage, Buttons={"Run away!"}}

-- [...] --

-- Somewhere, it will be called with...

-- [...] --


The trick is not to use a string variable but a Wherigo.ZMedia one. Please also note that the zmediaMessageImage object doesn't have Resources associated with it. I'm not sure it has to be this way but it works because it will never be really used (since this object will be assigned programmatically to the value (or address) of another Wherigo.ZMedia object).

  • Helpful 1
Link to comment

Sorry one more question, when I call "myMsgBox(zmediaMonsterImage)" is it possible to switch the image without changing the call? I am trying to only use a single message and was hoping to avoid a long string of if/else statements. There are about  30 different images that I need to assign to the one message.

Link to comment
19 hours ago, Forest-Ghost said:

Sorry one more question, when I call "myMsgBox(zmediaMonsterImage)" is it possible to switch the image without changing the call? I am trying to only use a single message and was hoping to avoid a long string of if/else statements. There are about  30 different images that I need to assign to the one message.


It all depends on how (and where) you make the call.


For instance, you could try to use an array of media.

Edited by Tungstène
misplaced parenthesis
Link to comment

Another option is to make use of the loadstring function. I don't know if all Wherigo players deal with this. (I only tried with webwigo).


-- Name all your monsters' images the same but with another number at the end.
zmediaMonster1 = Wherigo.ZMedia(cartMonsters)
zmediaMonster1.Id = "7331b9fbcecf795c26ca5fd6fc94a05d"
zmediaMonster1.Name = "Monster1"
zmediaMonster1.AltText = ""
zmediaMonster1.Resources = {
    {Type = "jpg", Filename = "Monster1.jpg", Directives = {}}
zmediaMonster2 = Wherigo.ZMedia(cartMonsters)
zmediaMonster2.Id = "c06af43a0f9f54ea684c3175e223c798"
zmediaMonster2.Name = "Monster2"
zmediaMonster2.AltText = ""
zmediaMonster2.Resources = {
    {Type = "jpg", Filename = "Monster2.jpg", Directives = {}}
zmediaMonster3 = Wherigo.ZMedia(cartMonsters)
zmediaMonster3.Id = "5bca6f26cfa5f26b9854446d8ae35fe0"
zmediaMonster3.Name = "Monster3"
zmediaMonster3.AltText = ""
zmediaMonster3.Resources = {
    {Type = "jpg", Filename = "Monster3.jpg", Directives = {}}
zmediaMonster4 = Wherigo.ZMedia(cartMonsters)
zmediaMonster4.Id = "a21031a7d4e6f429ad05f8df976d255f"
zmediaMonster4.Name = "Monster4"
zmediaMonster4.AltText = ""
zmediaMonster4.Resources = {
    {Type = "jpg", Filename = "Monster4.jpg", Directives = {}}
zmediaMonster5 = Wherigo.ZMedia(cartMonsters)
zmediaMonster5.Id = "5168eff92c56b75f089e61642ab4a6b6"
zmediaMonster5.Name = "Monster5"
zmediaMonster5.AltText = ""
zmediaMonster5.Resources = {
    {Type = "jpg", Filename = "Monster5.jpg", Directives = {}}
zmediaMonster6 = Wherigo.ZMedia(cartMonsters)
zmediaMonster6.Id = "465bab0d8e1d457cb32b673e2fe98489"
zmediaMonster6.Name = "Monster6"
zmediaMonster6.AltText = ""
zmediaMonster6.Resources = {
    {Type = "jpg", Filename = "Monster6.jpg", Directives = {}}

-- This is the media we'll use in the messageBox. No ressources needed.
zmediaPlaceHolder = Wherigo.ZMedia(cartMonsters)
zmediaPlaceHolder.Id = "e89bc0f3a7c5edafb35180e44b202c11"
zmediaPlaceHolder.Name = "PlaceHolder"
zmediaPlaceHolder.AltText = "A monster!"
zmediaPlaceHolder.Resources = {}

-- A global variable holding the number of the next monster to be shown.
var_monsterNumber = 1

-- In this demo, a timer will trigger the monster message (after 5 seconds).
ztimerHourglass = Wherigo.ZTimer(cartMonsters)
ztimerHourglass.Id = "360401d881bc863a1d74a014893c97a7"
ztimerHourglass.Name = "Hourglass"
ztimerHourglass.Type = "Countdown"
ztimerHourglass.Visible = false
ztimerHourglass.Duration = 5

-- At the beginning, let's choose the first monster to appear and start the timer.
function cartMonsters:OnStart()
    zmediaPlaceHolder = zmediaMonster1

-- Monster is approaching! Look at its photograph: it never is the same ;-)
function ztimerHourglass:OnTick()
    Wherigo.MessageBox {
        Text = "Oh look! There is a monster here!",
        Media = zmediaPlaceHolder,
        Buttons = {"Run away!"},
        Callback = cartMonsters.MsgBoxCBFuncs.MsgBoxCB1

-- When we run away (i.e. when we click on the messageBox button), we choose
-- another monster number and we start the timer again.
cartMonsters.MsgBoxCBFuncs.MsgBoxCB1 = function(action)
    var_monsterNumber = var_monsterNumber + 1
    if (var_monsterNumber > 6) then
        var_monsterNumber = 1
    -- Next line is where the trick lies ;-)
    loadstring("zmediaPlaceHolder = zmediaMonster" .. var_monsterNumber)()

-- [...] --


  • Love 1
Link to comment

Thank you so much! Okay I finally got it to work. I see now I did not setup the original example you sent me. But after working through the new example I was able to switch through the images on the same message. Most of my coding knowledge revolves around dragging things in urwigo, so when it comes to actual Lua coding I really struggle with getting the code to work. Anyway, a huge thank you again. I really appreciate your help!! 

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.

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.

Followers 2
  • Create New...