Ask a Question related to Macromedia Director Lingo, Design and Development.
-
Nubber webforumsuser@macromedia.com #1
Changing a sprite member for a period of time
Dear Forum
I have developed a childs numeracy and spelling game. I have managed to build the back-end of the system i.e the creation of random questions etc, but now I am working on the visual front-end side.
What I am trying to do is build a function to display a particular sprite for a period of time (that I can set).
The function that will reside in my main movie script that will take parameters such as the duration to show & the sprite member name/number that I wish to show.
The idea is that when the child gets a question correct I will call the function and it will make a sprite visible such as ?Well done!? Or if it is wrong ?Hard luck?, I will also be using some graphics so the idea of using a text field isn?t any good.
I have tried to use the .visible and .blend functions to hide the sprites will be in the background all the time, yet I have no idea how to do the show the sprites for a specified duration and then set them back to invisible.
Because the game runs all from one frame I do not want to jump to another frame to display a graphic etc as this will lose the position in the game.
Any help suggestions would be great.
Thanks
Nubber webforumsuser@macromedia.com Guest
-
Allowing opening pdf for a period of time
Is there a way to create a pdf so that when provided to users, there is a time limit on opening it??? In other words, I have material that is... -
Logging someone out of a site after a certin time period
Can someone help me. I have created a login form and used Application.cfm to hold my login and loginuser. I would like to know if anyone knows how... -
How can I avoid the mouse click during a short period of time???
Hello to all!!! I have a projector movie that opens another projector movie when a specific button is clicked. It works fine , but, if the... -
maintaining sprite position when changing cast member
It should apear in the same place. If it's a bitmap or vector check the registration point in the bitmap or vector editors. Des -
Loop for a period of time.
Hello everyone. I am making a auto play slide show of about 50 images. How can i make director loop on a image for say 10 seconds before moving... -
Word of Mouth Productions #2
Re: Changing a sprite member for a period of time
I think you'd be better off with a behavior rather than a movie script so I
will proceed with that in mind. You can engage a sprite using:
SendAllSprites (#EngageTimer, #correct, 120, "correctAnswerNumber3")
This will show any sprite that has #correct assigned to the pNoteType
parameter for 2 seconds (120 ticks) Of course you can change the handler
names, add many more pNoteType values in the getPropertyDescriptionList
handler but I hope this is a start.
property pS, pTimer, pVisibleDuration, pNoteType
on getPropertyDescriptionList
return [#pNoteType: [#comment: "Choose note type:", #format: #symbol,
#default: #none, #range: [#correct, #incorrect]]]
on beginSprite me
pS = sprite (me.spriteNum)
pTimer = 0
pVisibleDuration = 0
pS.visible = FALSE
end
-- noteType would be the way you tell all sprites which have this behavior
attached
-- which sprite should display a member
-- visibleDuration is the length of time in ticks for which the sprite will
be visible
on EngageTimer me, noteType, visibleDuration, memName
if noteType = pNoteType then
pTimer = the ticks
pVisibleDuration = visibleDuration
pS.member = member memName
pS.visible = TRUE
end if
end
on exitFrame me
if pTimer <> 0 then
if the ticks > pTimer + pVisibleDuration then
pS.visible = FALSE
pTimer = 0
pVisibleDuration = 0
end if
end if
go to the frame
end
--
Craig Wollman
Word of Mouth Productions
phone 212 724 8302
fax 212 724 8151
[url]www.wordofmouthpros.com[/url]
"Nubber" <webforumsuser@macromedia.com> wrote in message
news:bhg98h$ino$1@forums.macromedia.com...build the back-end of the system i.e the creation of random questions etc,> Dear Forum
>
> I have developed a childs numeracy and spelling game. I have managed to
but now I am working on the visual front-end side.for a period of time (that I can set).>
> What I am trying to do is build a function to display a particular spriteparameters such as the duration to show & the sprite member name/number that>
> The function that will reside in my main movie script that will take
I wish to show.function and it will make a sprite visible such as ?Well done!? Or if it is>
> The idea is that when the child gets a question correct I will call the
wrong ?Hard luck?, I will also be using some graphics so the idea of using a
text field isn?t any good.will be in the background all the time, yet I have no idea how to do the>
> I have tried to use the .visible and .blend functions to hide the sprites
show the sprites for a specified duration and then set them back to
invisible.frame to display a graphic etc as this will lose the position in the game.>
> Because the game runs all from one frame I do not want to jump to another>
> Any help suggestions would be great.
>
> Thanks
>
>
>
>
Word of Mouth Productions Guest
-
Roofy webforumsuser@macromedia.com #3
Re: Changing a sprite member for a period of time
I think you'd be better off with a behavior rather than a movie script so I
will proceed with that in mind. You can engage a sprite using:
SendAllSprites (#EngageTimer, #correct, 120, "correctAnswerNumber3")
This will show any sprite that has #correct assigned to the pNoteType
parameter for 2 seconds (120 ticks) Of course you can change the handler
names, add many more pNoteType values in the getPropertyDescriptionList
handler but I hope this is a start.
property pS, pTimer, pVisibleDuration, pNoteType
on getPropertyDescriptionList
return [#pNoteType: [#comment: "Choose note type:", #format: #symbol,
#default: #none, #range: [#correct, #incorrect]]]
on beginSprite me
pS = sprite (me.spriteNum)
pTimer = 0
pVisibleDuration = 0
pS.visible = FALSE
end
-- noteType would be the way you tell all sprites which have this behavior
attached
-- which sprite should display a member
-- visibleDuration is the length of time in ticks for which the sprite will
be visible
on EngageTimer me, noteType, visibleDuration, memName
if noteType = pNoteType then
pTimer = the ticks
pVisibleDuration = visibleDuration
pS.member = member memName
pS.visible = TRUE
end if
end
on exitFrame me
if pTimer <> 0 then
if the ticks > pTimer + pVisibleDuration then
pS.visible = FALSE
pTimer = 0
pVisibleDuration = 0
end if
end if
go to the frame
end
--
Craig Wollman
Word of Mouth Productions
phone 212 724 8302
fax 212 724 8151
[url]www.wordofmouthpros.com[/url]
"Nubber" <webforumsuser@macromedia.com> wrote in message
news:bhg98h$ino$1@forums.macromedia.com...
Craig,
This sounds like a handy tool to know, though when you only have 2 sprites for one is the sprite that displays correct, and the other sprite displays incorrect, why make the computer do all that work to find out if that sprite is the correct or wrong answer especially if Nubber has a total of 100 or more sprites that have nothing to do with the sprite that Nubber wants to put the timer on.
Nubber,
You can create this 2 different ways.
1. The first way is to create a property list that in each list has a the question, and the correct answer to that question. This way when the user types in an answer you can create a handler that checks what the user had typed in and compare it to your list. Yes this will take a little processing time but only in the initialization time instead of every single time the user types in an answer. Also creating a property list in the long run will also use less sprites and less processing time when the user types in his/her answer. Meaning you would only need a total of 2 sprites, one for displaying the question, and the other to display whether the user gets the answer correct or incorrect which will also lessen the processing time as well.
2. if you didn't want the property list to hold all the information, you can create the list to only have the correct answers, and then compare that to what the user typed in. This could be another solution if you know that the first way wouldn't be suitable to what your doing.
Now, no matter which one you choose, building this we will use the "start timer" event.
****Preparing the cast library****
Create a new Cast Library that will proceed to the choice above you decide to choose and name it "Q&A" without the quotes.
If you choose the first choice, then have your cast members in this order...
member 1 will have question #1
member 2 will have the answer to question 1.
member 3 will have question #2
member 4 will have the answer to question 2
member 5 will have question #3
member 6 will have the answer to question 3
.... and so on
.... this will make the repeat loop easier to initialize the property list
****Building the behaviour script****
property pData
property pQuestionNum
on beginSprite
pData = []
pQuestionNum = 1
initDataList()
displayQuestion()
end beginSprite
on initDataList
tempProp = [:]
repeat with i = 1 to the number of members of castLib("Q&A")
tempProp = [#question: member(i, "Q&A").text, #answer: member(i + 1, "Q&A")
add pData, tempProp
i = i + 1 -- you add one to this because you want "i" to skip 2 steps. So when "i" = 1, in the next loop "i" will be 3 etc.
end repeat
on displayQuestion
sprite(x).member.text = pData[pQuestionNum].question --where x is the sprite number that your displaying the question
end displayQuestion
--- this hander gets called when the user clicks on the "next" button
on nextQuestion me
pQuestionNum = pQuestionNum + 1
displayQuestion
-- this handler gets called when the use clicks on the "check Answer" button
on checkAnswer
--*note x is the sprite number to the sprite that the user is typing the answer in
if sprite(x).member.text = pData[qQuestion].answer then
--*note x is the sprite number that holds the "Correct" or "wrong" member
sprite(x).blend = 100
sprite(x).member = member("Correct Answer")
else
--*Note x is the sprite number that holds the "Correct or "wrong" member
sprite(x).blend = 100
sprite(x).member = member("Wrong Answer")
end if
--*Note x is the sprite number that the user types in his/her answer.
sprite(x).member.text = " " --this will clear the string of textif
startTimer -- Like I said previously this will tell when to switch the sprite blend back to 0 in the "on exitFrame" handler
end checkAnswer
on exitFrame
--*Note x is the sprite number that is holding the "Correct" or "Wrong" member
if sprite(x).blend = 100 then
if the timer > 120 then -- 120 stands for 120 ticks or 2 seconds
sprite(x).blend = 0
end if
end if
go to the frame -- make this frame repeat itself
end exitFrame
now drag this behaviour to the frame script section of the score to the frame that you want this behavior to happen on
****Building the next button behaviour script****
on mouseUp me
sendSprite(0, #nextQuestion)
end mouseUp
now drag this to your "next" button sprite
***Building the "Check Answer" behaviour script****
on mouseUp me
sendSprite(0, #checkAnswer)
end mouseUp
now drag this to your "Check Answer" sprite
that's all folks
Roofy webforumsuser@macromedia.com Guest
-
Nubber webforumsuser@macromedia.com #4
Re: Changing a sprite member for a period of time
Hi
Thanks for your feedback on the subject, my apologies for not replying sooner I have been out of the office.
I understand completely about what youe mean in terms of using object oriented principles, I have used Java extensively for the past two years and understand how useful it can be.
I found out a solution for my problem that suited my needs, its rough and ready but for the requirements it is more than acceptable, the main reason being that Its not a problem that it holds up intreractivity as I do not want anything to be interacted with whilst the sprite is in a swapped state.
Here is the code, rough and not perfect but it does the job for the time being.
--------------------------------------------------------------------------------------------
-- Function that will swap a spite member for another for a specified duration
--------------------------------------------------------------------------------------------
on swapSprite spTarg, spSub, secs
-- Get the name of the sprites original member state
currentSprite = sprite(spTarg).member.name
-- sets the timer to zero
startTimer
repeat while the timer < (secs*60)
-- During the time specified set the target sprite member to one specified
sprite(spTarg).member = member(spSub)
-- Refresh the contents of the stage (VERY IMPORTANT!)
updateStage
end repeat
-- Once time period complete return sprite to state
sprite(spTarg).member = member(currentSprite)
end
Thanks again
Nubber webforumsuser@macromedia.com Guest
-
Word of Mouth Productions #5
Re: Changing a sprite member for a period of time
I would never argue with something that ultimately delivers what you need.
But repeat loops not only steal interactivity from the Director projector
but often from other machine activties. There's also something to be said
for doing something that will further one's experience even though a simpler
more familiar solution works.
I'll leave the rest up to you.
Another comment on your way of doing it. It would be better to change the
sprite before the repeat loop. There's no need for that to take place in
the repeat loop nor is there any reason to have an updateStage in the loop.
Again, you won't necessarily see the difference but in a situation where it
will make a difference it's better to have the experience of doing things
more efficiently.
Craig Wollman
Word of Mouth Productions
phone 212 724 8302
fax 212 724 8151
[url]www.wordofmouthpros.com[/url]
"Nubber" <webforumsuser@macromedia.com> wrote in message
news:bhmgm6$si5$1@forums.macromedia.com...sooner I have been out of the office.> Hi
>
> Thanks for your feedback on the subject, my apologies for not replyingoriented principles, I have used Java extensively for the past two years and>
> I understand completely about what youe mean in terms of using object
understand how useful it can be.ready but for the requirements it is more than acceptable, the main reason>
> I found out a solution for my problem that suited my needs, its rough and
being that Its not a problem that it holds up intreractivity as I do not
want anything to be interacted with whilst the sprite is in a swapped state.being.>
> Here is the code, rough and not perfect but it does the job for the time------------------>
> --------------------------------------------------------------------------duration> -- Function that will swap a spite member for another for a specified------------------> --------------------------------------------------------------------------specified>
> on swapSprite spTarg, spSub, secs
>
> -- Get the name of the sprites original member state
> currentSprite = sprite(spTarg).member.name
>
> -- sets the timer to zero
> startTimer
> repeat while the timer < (secs*60)
>
> -- During the time specified set the target sprite member to one> sprite(spTarg).member = member(spSub)
>
> -- Refresh the contents of the stage (VERY IMPORTANT!)
> updateStage
> end repeat
>
> -- Once time period complete return sprite to state
> sprite(spTarg).member = member(currentSprite)
> end
>
> Thanks again
>
>
Word of Mouth Productions Guest



Reply With Quote

