Game Academy help: Lesson 1: activateScreenUpdates error

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
zacksquatch
Posts: 2
Joined: Wed May 01, 2013 10:32 pm

Game Academy help: Lesson 1: activateScreenUpdates error

Post by zacksquatch » Wed May 01, 2013 10:37 pm

I have been watching the Game Academy videos, and when I run script that makes the rocket fall, about 30 minutes in, it has an error that reads:
card id 1002: execution error at line 16 (Handler: can't find handler) near "activateScreenUpdates", char 1

I have done everything I have been told to do, and I have searched for mistakes, and found none. How do I fix this?

Please help

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Game Academy help: Lesson 1: activateScreenUpdates error

Post by sturgis » Wed May 01, 2013 10:48 pm

Can you post your stack? Hard to say whats missing without digging into the code.

YOu do have the game loop code placed in the stack script right? (not sure the game academy goes through all that code, but it should be in the stack script that is part of the game academy resources) Worst case if you don't have the code I can post it here so that you can add it to your stack script.

Of course if you DO have that code in your stack, i'd still need to see the rest of the code to figure out whats up.

zacksquatch
Posts: 2
Joined: Wed May 01, 2013 10:32 pm

Re: Game Academy help: Lesson 1: activateScreenUpdates error

Post by zacksquatch » Thu May 02, 2013 10:19 pm

local sGameRunning

on updateScreen

if sGameRunning then

if the mouse is not down then
set the top of image "myrocket" to the top of image "myrocket" + 10
end if

end if

end updateScreen

on StartGame
activateScreenUpdates

put true into sGameRunning
end StartGame

on stopGame
put false into sGameRunning
end stopGame

This obviously isn't a "loop," but this is what the scripting was on the video and it worked in that.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Game Academy help: Lesson 1: activateScreenUpdates error

Post by sturgis » Thu May 02, 2013 10:37 pm

Right. THere is actually a separate script in the stack that runs the game loop.

the updatescreen message is a message that is dispatched by that game loop so that every so often your "updatescreen" handler will do its thing.

on StartGame is a handler that is called most likely by a mouseup, and it is the one that starts the game loop running. activatescreenupdates is the handler that actually starts the game loop and sets your sGameRunning flag. stopgame leaves the loop running but puts false into the sGamerunning flag.


Here is the script that should be added to the stack. I'm not sure its the most recent/perfect version, but its the one I can find on-hand:

Code: Select all

local sStartUpdateTime
local sFrameRate
local sUpdateMessageId
local sScreenUpdateActive

on activateScreenUpdates
   
   if not sScreenUpdateActive then
      put true into sScreenUpdateActive
   else
      exit activateScreenUpdates
   end if
   
   set the acceleratedRendering of this stack to true
   startUpdatingTheScreen 50
   
end activateScreenUpdates

on startUpdatingTheScreen pFrameRate
   put pFrameRate into sFrameRate
   put 0 into sStartUpdateTime
   send "dispatchUpdateScreen" to me in 0 millisecs
   put the result into sUpdateMessageId
end startUpdatingTheScreen

on stopUpdatingTheScreen
   if sUpdateMessageId is not empty then
      cancel sUpdateMessageId
   end if
   put empty into sUpdateMessageId
end stopUpdatingTheScreen

on dispatchUpdateScreen
   local tThisFrameTime
   put the long seconds into tThisFrameTime
   
   if sStartUpdateTime is 0 then
      put the long seconds into sStartUpdateTime
   end if
   
   lock screen
   dispatch "updateScreen" to this card with tThisFrameTime
   unlock screen
   
   local tTheTimeNow
   put the long seconds into tTheTimeNow
   
   local tNextFrameCount
   put round((tTheTimeNow - sStartUpdateTime) * sFrameRate + 0.5) into tNextFrameCount
   send "dispatchUpdateScreen" to me in (sStartUpdateTime + (tNextFrameCount * (1 / sFrameRate)) - tTheTimeNow) seconds
   put the result into sUpdateMessageId
end dispatchUpdateScreen

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Game Academy help: Lesson 1: activateScreenUpdates error

Post by sturgis » Thu May 02, 2013 10:46 pm

Just looked at the lesson and in the section of the background reading, page 5 (from the materials you can download) it says:

Constructing a game loop
Implementing a game loop structure in LiveCode can be accomplished in a variety of ways, and indeed it is a trivial task to create a very basic one. However, for the purpose of this academy, we are going to use a highly robust game loop construct, which will be included with the materials you are given during the academy. The code, for those interested in seeing how it functions, will be located in the stack script of our livecode files.

So if you've grabbed the materials and stacks and resources for building the game, the script should be in the stack script of the basic stacks.

Read that whole section of the background reading its pretty helpful in understanding what is going on.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Game Academy help: Lesson 1: activateScreenUpdates error

Post by sturgis » Thu May 02, 2013 10:57 pm

Also noticed the script you posted is the very very first "gravity" script. Says "if the mouse is not down.." it will make the rocket fall till it reaches the bottom of the script. With the stack script in place, this works fine for me, but there is no "up" code. Depending on which stack you look at in the materials (like in the solutions stacks there is a "move up" stack...) this is solved.

If you have trouble or questions as far as getting the first stages working feel free to ask. I'll go through the course so i can get an idea of where info can be located so I can maybe help.

Post Reply