Script "Rules"

Started by Joseph, Mon 15/06/2009 23:08:32

Previous topic - Next topic

Joseph

Hola Amigos!

My first attempt at a weird script thing:

Im trying to get this script to work correctly, but I can't seem to make it work.

If I do this, everything is just fine--->
DateTime *dt = DateTime.Now;
Display ("The time is: %02d:%02d:%02d", dt.Hour, dt.Minute, dt.Second);

But what are the "script rules" if I want to display the exact same thing, but with DisplayAt? What I mean by rules is...the "grammatical priority" of brackets, /", {}...etc.

Im getting mixed-up with where to put the parenthesises...Ive tried many many varations without any luck and I think my brain is gonna blow! LOL

For example, this doesn't work--->

DisplayAt (700, 400, 370, "The time is: %02d:%02d:%02d", dt.Hour, dt.Minute, dt.Second");

???
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Trent R

I've never used DisplayAt, but you can best solve your problem with this:
Code: ags
DateTime *dt = DateTime.Now;
String time=String.Format("The time is: %02d:%02d:%02d", dt.Hour, dt.Minute, dt.Second)
DisplayAt (700, 400, 370, time);


As for your other questions, I don't have time right now to answer, but someone else will, or you can check out the Scripting tutorial in the manual.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

GuyAwesome

#2
Actually, I think it's simpler than that. You have an extra " at the end of the line, before the final ) - dt.Second"); - which will cause a compilation error ('end of input reached in middle of expression'). You can use Ctrl-B on all braces and quotation marks to make sure they match up - the usual cause of that error. Otherwise it works fine as-is, provided you've still got the DateTime *dt = DateTime.Now; line in as well. (I'm assuming your resolution is high enough that 700,400 is on screen :))

In the future, it's helpful if you say WHY/HOW something isn't working as best you can (error messages, crashing, just not doing as expected...), but beyond that the manual examples and scripting tutorial are good places to start to pick up the rules. And always check braces, quotation marks, capitalisation, semi-colons at line ends, etc. It's the simple things that cause the most hair-tearing frustration, in my experience.

Joseph

I wasnt aware of the String.Format function...thats exacly what I needed. All is ok now.
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

SMF spam blocked by CleanTalk