PDA

View Full Version : Something neat I discovered about ZScript



itsyfox
01-12-2007, 05:32 PM
Alright. I'm at the moment trying to learn ZASM. It doesn't look too hard once I know the commands, but the problem is, I haven't been able to dig up the thread yet where the commands were initially explained, so I only get any commands when someone asks, 'what's wrong with this script' and you see some of them in use.

However, when compiling a script in ZScript once, I was going to test it in ZC. I'd been doing a lot of Trace()'s to see how my math was working, so I had a routine: Re-write script, Open ZQuest, import script, compile script, save to slot, save and quit ZQuest, open ZC, delete and restart my file, test the script, close ZC, open Allegro.log...

Well, I got mixed up. After saving and closing ZQuest, I opened Allegro.log. Scrolling down towards the bottom, I started seeing ZASM.

"Whoa! How'd I do that? Oh! I didn't run ZC yet! This is from ZQuest!"

So. If you know ZScript but not ZASM, and you want to see what your scripts are compiling to, you can use this method. ^_^

I dunno if this was already gone over before, if anyone discovered it before, or if it was already common knowledge.

I just figured it out by accident, so thought I'd share. ^_^

DarkDragon
01-15-2007, 11:11 AM
Yup, it's a "hidden feature" I put in to help debug the ZScript compiler, since when a ZScript misbehaves it's not always clear where to begin.

You can get a pretty complete understanding of how the compiler breaks down ZScript code by studying the ZASM output.

itsyfox
01-15-2007, 12:43 PM
Which is good!

Because now I've pretty much got Tkinter figured out, I've got an interface design figured out, and I might even be able to do some skinning using the Canvas widget, even though so far people seem to feel it can't be done...

As long as the widget can extend beyond the window border and 'decorations'. I believe there's a 'draw directly on screen' option for that. So I'll be set. ^_^

By the way, I figure I can just make the first version of my little multi-language compiler for Windows using Py2exe, since there's only a beta with scripting for Windows currently (isn't that right? Or is there a linux/mac version for any of the previous betas since the one that introduced scripting?).

Eventually however, I'm going to wrap it in C, and hope to bind all my resources (including python files and Tkinter) into the executable, if that doesn't bulk it out too bad and can be done. Otherwise, there'll have to be a subfolder and it'll need to be zipped or rar'ed. :/

Actually, no matter what there's gonna be multiple files. The bulk of the workings should be in the main program, but there will be a few python files left in the main directory that can be modified, and hopefully new ones added. The first of these will contain a dictionary of {"Python": "ZASM"} comparative commands, and the second will be a file full of try-excepts and their respective error messages to print in the compile window.

I'm going to include warnings and errors for as many things as I can find/think of, and there's also going to be a tab in configuration where you can check/unckeck certain warnings (for instance, since this bug is likely to be fixed soon (if beta 16c doesn't already?), use of this-> in an FFC script will (unless unchecked) get a general warning not to use that on any FFC but the first, and to instead make explicit reference to the right FFC).

Anyways, the point of this post is, yay for seeing ZASM in Allegro.log, because then I can look at it side-by-side with my ZScripts! I already learned that your way of dealing with ZScript functions is with GOTOLESS and GOTOMORE commands, that's at brief glance, I still don't know how you tell it WHICH line to return to (unless there's RETURN, or perhaps you use a global variable?). But I'll be able to once I look more closely. Right now I'm working on the interface, the 'compiler' will come next, and in a seperate file that will be imported into the main one, and its classes used to make the conversions.

BTW, I think I might call this thing 'Rope'. So many Python apps have to either make reference to Monty Python, or a snake. I choose the latter because it can tie in with Zelda Classic. ^_^ Also, heh. 'Tie in'. Kind of what it's doing, isn't it?

DarkDragon
01-16-2007, 11:09 AM
Uh, I believe functions are called using a simple GOTO. To return, the return value is pushed onto the stack, then popped and GOTORd at the end of the function.

Dark Nation
01-16-2007, 11:23 AM
You can also use the output to streamline your scripts. First, hammer out your script in ZScript until it works like you want (after testing). Then, do a final compile and hand-edit the ZAsm that's generated to clean things up a bit. Then, save the cleaned ZAsm code to a .z file and import into ZQuest. This is pretty much only useful if you want to squeeze every last drop of performance out of your script. Plus it helps you learn/understand ZAsm! :D

itsyfox
01-16-2007, 10:32 PM
Yes, indeed it does! I need to do that with bomb_refill and raft_game.

I also need to clean raft_game up like I've wanted to for a while and post it. My only problem now is some of the rupees that are supposed to pop up randomly are staying at 0,0 while others ARE appearing in random locations (that are also on exact tiles with the raft flag, so link can pick them up properly). I've solved this temporarily by making the FFC draw-over and setting its combo to the same as the water around it. And I raised the number of produced rupees to make up for the number that typically don't leave 0,0 (between 2 and 5, it seems, usually staying on the low end but sometimes when I have it produce 5 or less rupees none show up at all. o_O).

But, I'm wandering topic again. The whole reason for learning ZASM is to make my compiler, and I currently have the barebones main interface nearly done. None of the buttons do anything yet and I have two custom combo boxes without dropdowns, but I have all the menu entries (except for cut, copy and paste in the edit menu, which I forgot >_<), both buffers, the Import/Export buttons and the Compile button, and the one thing you can click that does something besides send "Hello!" to the Python Interpreter is Exit under the File menu. ^_^

I think I'll post screenshots soon. I wonder if I should post links in this thread, or make a new one, and if so, where...

I'll find wherever the MapMaker/ZCLauncher threads are posted and post on that forum.