Set the icon to (icon of another stack)--YES!

Rob Cozens rcozens at pon.net
Wed Jan 4 19:39:06 EST 2006


Paul, Ken, et al,

It's alive!

My icon-changing stack, "Chameleon" is now changing icons on-the-fly.

Chameleon stack script:

local imagePath1,imagePath2,currentLibrary

on openStack
   get the effective fileName of this stack
   set the itemDelimiter to "/"
   put "X2.rev" into item -1 of it
   put it into imagePath1
   put "X3.rev" into item -1 of it
   put it into imagePath2
   start using stack imagePath1
   put imagePath1 into currentLibrary
   refreshButtons
end openStack

on switchLibraries
   set the itemDelimiter to "/"
   get item -1 of currentLibrary
   if it is "x3.rev" then
     stop using stack imagePath2
     close stack imagePath2
     start using stack imagePath1
     put imagePath1 into currentLibrary
    else
     stop using stack imagePath1
     close stack imagePath1
     start using stack imagePath2
     put imagePath2 into currentLibrary
   end if
   send "refreshButtons" to this stack in 1 tick
end switchLibraries

on refreshButtons
   repeat with x = 1 to the number of buttons
     set the icon of button x to (the icon of button x)
   end repeat
end refreshButtons

The key to making this work was sending "refreshButtons" to the stack 
instead of calling it from the handler that switches the libraries. 
Also, one must close the previous library [with destroyStack true], 
not just stop using it.

So all you game builders who want to change the look and difficulty 
as the user reaches each new level could address that with multiple 
libraries containing images with the same icon id and handlers with 
the same name but different logic.

It's gratifying when one's long-term hunch proves to be correct.  :{`)

Rob Cozens CCW
Serendipity Software Company

"And I, which was two fooles, do so grow three;
  Who are a little wise, the best fooles bee."

  from "The Triple Foole" by John Donne (1572-1631)




More information about the use-livecode mailing list