Articles Archive
Articles Search
Director Wiki
 

Dynamic cast updating

April 20, 1998
by Pat McClellan

Dear Multimedia Handyman,

I'm making a Director 6 game which has 3 rounds and 5 questions per round. I am creating a section in the score for displaying the question, but I want it to update itself dynamically based on which round and question the user is on. Each question displays the question text and 2 images. How is the best way to make this work?

Jane Shannon

Dear Jane,

Your approach is very smart. Rather than lay out each question in the score, you're just laying it out once and updating the cast members assigned to the sprites. The trick to making this update process easy is to use a naming convention. Then, reference these names dynamically in your sprite's behavior scripts.

Let's keep track of which round and question we on using global variables: gWhichR and gWhichQ. When the game starts, you'll set both of these to 1, then after each question set gWhichQ = gWhichQ + 1. When gWhichQ exceeds the number of questions in the round, then reset gWhichQ to 1 and set gWhichR = gWhichR + 1.

How can you use this information so that the sprites get updates?

Start by naming your cast members according to a naming convention. For example, for round 1 question 1 text, we'll use: r1q1text. For the 2 images for that same question, we'll use: r1q1image1 and r1q1image2. Now we're set to reference these members from our behavior script.

This behavior allows the author to set which type of cast member it should be... the question text or one of the 2 images to be displayed with the question. Then, it assigns it to the sprite. This process only happens when the sprite is first encountered and then "turns itself off" until gWhichQ changes. At that point, pDisplayed Q <> gWhichQ, so the sprite will reset its cast member.


property pDisplayedQ   
property pMyType        

global gWhichR, gWhichQ

on getPropertyDescriptionList
  set MemberTypeList = ["text", "image1", "image2"]
  set p_list = [ Â
        #pMyType: [ #comment:   "Index:", Â
                    #format:    #symbol,Â
                    #default:   "", Â
                    #range:     MemberTypeList ]Â
                 ]
  return p_list  
end

on beginSprite me
  set pDisplayedQ = gWhichQ
end

on prepareFrame me
  if pDisplayedQ <> gWhichQ then
    set mySprite = the spriteNum of me
    set whichMember = "r" & gWhichR & "q" ¬
	  & gWhichQ & pMyType 
    set the member of sprite mySprite to  ¬
	  member whichMember
    set pDisplayedQ  = gWhichQ
  end if
end

The use of naming conventions and some simple text parsing in your behaviors can be used to create some very powerful, "smart" sprites. Good luck with your project.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.