Posts filed under 'Basic Lingo'
People occasionally have questions when trying to find a ceiling or floor function in the Lingo library so I figured I’d post it here for future googlers.
Lingo didn’t include these two math functions, but you can write your own functions and keep them in your personal library of goodies.
on floor aFloat
return integer(aFloat) - (aFloat < integer(aFloat))
end
on ceil aFloat
return integer(aFloat) + (aFloat > integer(aFloat))
end
If you are working with Javascript these functions are built in:
Math.ceil(aFloat);
Math.floor(aFloat);
February 3rd, 2009
One thing about Director is that the help files are often missing things. One key thing is time (I heard it keeps on ticking). Think about all these different things (roughly grouped) – feel free to start typing in the message window.
the ticks
_movie.ticks()
the milliseconds
_system.milliseconds
the date
the long date
_movie.date()
_system.date()
the time
the long time
_movie.time()
_system.time()
the systemDate
_movie.systemDate()
_movie.systemDate().year
_movie.systemDate().month
_movie.systemDate().day
_movie.systemDate().seconds
What are all these things? Well…some are old, some are new, some are undocumented, and some are blue (ok…maybe not). Running a little script to show each of those items you get the following:
— “2861209 = the ticks”
— “2861210 = _movie.ticks()”
— “47686843 = the milliseconds”
— “47686848 = _system.milliseconds”
— “3/2/08 = the date”
— “Sunday, March 2, 2008 = the long date”
— “3/2/08 = _movie.date()”
— “3/2/08 = _system.date()”
— “8:14 PM = the time”
— “8:14:21 PM = the long time”
— “8:14 PM = _movie.time()”
— “8:14 PM = _system.time()”
— “date( 2008, 3, 2 ) = the systemDate”
— “date( 2008, 3, 2 ) = _movie.systemDate()”
— “2008 = _movie.systemDate().year”
— “3 = _movie.systemDate().month”
— “2 = _movie.systemDate().day”
— “72861 = _movie.systemDate().seconds”
Here is the really quick explanation (as far as I know).
the ticks (or _movie.ticks) are divisions of time that are equal to approximately 1/60 of a second (slight variance on different platforms/computers). I’m not sure when they start counting (i.e. when would it show 0 ticks). the milliseconds (or _system.milliseconds) are the number of milliseconds (1/1000 of a second) that have passed since it started counting – and once again, I’m not sure when it starts counting. the date, _movie.date() and _system.date() all return the same value (at least in my case). I believe that the format of these will vary based on your international settings on your computer.
the long date provides the name of the day and the month. This is older Lingo. I’m not aware of a modern way to get this value. Does anyone know of anything such as _system.date.long() that might give the same information? The long date is rather unique (or should I say old?).
the time, _movie.time, and _system.time all provide the same value, but once again, there is the long time which includes the seconds and is unique and old. Does anyone know if there is a modern (dot syntax) version of that?
the systemDate (modern version is _system.date()) provides the date in the format of (year, month, day). This is supposed to be uniform across international systems. From this date you can easily get the year, month or day as was shown above. The most interesting part is that you can also get the seconds past midnight with the _movie.systemDate().seconds.
Between all those things you can usually come up with at least one time or date that seems interesting. Of course, if you want a bit more you could also use javascript or an actionscript object via lingo to get even more times and dates.
Some interesting resources related to this:
Director Online article
Mediamacros script
Using actionscript objects with date/time:
Director Dev Center Article
ActionScript dictionary for date objects
March 2nd, 2008
Back in 1996 there was an After Dark (I think) screensaver that morphed vector-like figures from one Olympic sport in to another, such as swimmer to a volleyball player. If I had the energy/time I’d look around on a backup CD for that one just to grab an image (if of course I could get OS8 or 9 up and running). Screensavers have mostly faded away with the exception of that really cool spinning 3D RSS Visualizer and the iTunes cover art on OSX. Anyway (enough reminiscing), I never forgot that screensaver and loved how things morphed.
When vectorShapes made it in to Director 7 I immediately started using them. They made such nice anti-aliased lines and curves (or is that aliased…which ever is the pretty one). For making graphs and such in math and science they are unbelievably useful.
One issue that many Director users have when first starting to use vectorShapes is when the registration point seems to shift around as you change the vertexList. There are proper things to do, but this covers a little trick that I use. One of the first things I noticed is that you could have two vertexPoints in your vector, and if they were less than 0.5 pixels apart that line wouldn’t show up in the vectorShape member. Nifty!
If you use this fact you can draw an invisible line in one corner of a rectangle, and another invisible line in the opposite corner (using the #newCurve feature of vectorShapes). You can then start adding any new shapes you want. Just be sure you never have a point that goes “outside” your rectangular region.
In this example I set up several key data sets that will be my “shapes” that I will morph. In this case I just used 4 points. I do a few loops to move them from one shape to the next (by extrapolating between the current shape and the one it is morphing towards). When it gets to the final shape it starts working back to the first shape (and vice versa). One thing I do is flip the y value in sign before I add the data to the vertexList. In science I always need a positive value of y to be upward (otherwise the world would be upside down!).
There is a much more complete article on Director Online that covers a lot of the morphing behavior, so jump over there for some code that is a bit cleaner than mine 🙂
Click to view example (pop up window)
Download this example (zip file, 28k)
August 22nd, 2006
I have barely touched the game world, but one common thing that shows up in many games is a bar that ticks down your last moments of time. A question for a countdown timer is often brought up in forums, and there are many examples of timers kicking around everywhere from the built in behaviors to other samples on the web.
Here is a really quick one that just reduces the size of a QD (quick draw) rectangle. It used the _system.milliseconds for checking time on the exitFrame of a behavior applied to the QD rect sprite.
Source code for countdown time
February 22nd, 2006
On the Adobe Director Forums someone posed a question about how to get started with a “virtual pet.” There are different ways to think about such things. As a physics guy I like to think about pets that obey rules of physics. In this example I set up a pet (let’s just say it is a dog) that will wander around on the screen. If you throw a bone (by clicking on the stage) it will head for that bone, but on occasion it will see something else of interest and forget about the bone. It slowly gets hungry, and if you don’t coerce it in to getting to the food bowl bad things will happen.
The behavior has a nifty “chase” algorithm in it. I’ll probably do more with this file in the future to expand upon my pet.
Can you call that a virtual pet?
The code uses a few DirMX 2004 specific features (named sprites), but could quickly be adjusted to run in older versions (these issues are commented in the code). The graphics in this one are rather primitive to say the least.
Walk to the bone source code.
February 19th, 2006
When people first begin learning Lingo it is very common to do things such as sprite(21).visible = 0 or member(155).color = color(200,0,0). However, it is always advantageous to create behaviors that don’t make use of “hard coded” numbers so that the behavior can be reused in the future without having to adjust the sprite or member numbers or names.
When I first started playing with Lingo my code was full of these hard coded things. Now when I look back at stuff from a decade ago it kills me. Of course, when under pressure I’ll slip in a few of those things at the very end of a project. I always wish I could avoid it, but time pressures often cause the brain to ignore reason.
On the Adobe Director Forum a question was raised about changing the color of text on a mouseEnter event without having to recode each behavior for different member numbers. A very simple way to do this is to write a behavior that allows you to choose the color you want as you drop the behavior on each text member that you apply the behavior to.
Sample file: text_color_rollover.zip
Once you have written a good behavior, you end up using it for many years and many projects.
February 17th, 2006
A question was brought up in the Macromedia forums related to menus with submenus, and how would one could make one that functioned similar to the ones at the top of the forums.
I would like to create a sub-navigation that looks something like this:
Nav1 | Nav2 | Nav3
sub1 | sub2 | sub3
Is it possible to hide the sub-navigation until one of the main navigation(Nav2) links is rolled over? Can I have it stay there until another main navigation link is hit or when the user is taken to another frame?
There are a lot of ways to create menus, ranging from using Flash, imaging lingo, and dynamically generated sprites. In the forum JB basically answered the question with the very basic approach that allows for very quick development of this sort of thing with just a few lines of code.
You can download a sample file that was done in DirMX 2004.
Source for menu_demo.dir
There is also an article on Director Online related to menus, and using One Sprite Widgets at LingoWorkshop can make complex menus.
February 15th, 2006