PDA

View Full Version : Learning The Lingo



jobe
30th July 2005, 02:04 PM
Hiya. I'm starting to get into director and am doing a unit based around it at uni this semester. I went out and bought a giant lingo book that has been of some help to me but there is a few things I cannot work out. The first is how to generate a random number in a script executed when a button is pressed and use that number to go to a specific frame.

The second bit I think would be simple, but I cannot work out how to generate the random number in Lingo.

jobe
30th July 2005, 04:36 PM
ach. I've got a rather annoying error I cannot shake. I have a global variable declared in one script, but cannot use it in another.

here is it's declaration


-- declares the global variable
global gCardType

-- it executes everytime the movie starts
on startMovie me
gCardType=#Heart
end


and in an exitframe script


on exitFrame me
_movie.go(_movie.frame)

if gCardType=#Heart then
...
end if

end

I've taken most of the code out where the "..." is for simplicity. I get the following error

Script error: Variable used before assigned a value

if gCardType=?#Heart then


TIA

arty
30th July 2005, 05:01 PM
Any script you use the global in, not just the one where you decalre it, needs the global line.

So in your exitframe script, you also need:


global gCardType

geektechnu
30th July 2005, 05:55 PM
Random numbers? You probably want something like...

on the button:

global myVariable -- your variable

on mouseUp me
myVariable = random(10) -- make number from 1 to 10 inclusive
go to myVariable -- sends playhead to that frame number
end

You may need to do simple maths to get a number in the range you want:

(random(11) - 1 + 5) -- generate numbers 5 to 15 inclusive
Or use the number as part of a string to refer to a marker name:

global myVar

myVar = 5
go to "marker" & myVariable -- goes to the marker named "marker5"

And as arty has pointed put, any time you need to use a global variable, you need to declare it at the top of your script.

Funny thing is, I teach a Director/Flash unit at Monash University, and my class will be covering this next week. :P

jobe
30th July 2005, 10:08 PM
ahh brilliant, works perfectly. Thanks

jobe
1st August 2005, 08:59 PM
ok another 2 Q... I know you can change (swap) the cast in a sprite with another cast member using for example


sprite(1).member = member "Bling"

And that will swap whatever is in sprite 1 with the cast member bling. I'm just trying to figure out how this works when sprite 1 has multiple cast members... Does it swap the cast member that is under the play head at that point in time (that is active/displayed on that frame)?

Also... So as above, it swaps the casts. The new casts occupies the same frames that the old ones did. Is there any way (in lingo) to add a completely new cast member to an empty sprite? possibly specifying it's start and end frames in the process.

I hope that makes sence

jobe
7th August 2005, 04:10 PM
so... no-one knows how to add a cast member to an empty sprite in the score via a script?