A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: [F9] SquidScript demo

  1. #1
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188

    [F9] SquidScript demo - Updated!

    For the non-believers (I'm talking to you, Squize, Ray and Chriserror - just kidding ), I have made a simple example of my xml-based scripting language for AS3.

    The example contains a small script (hard-coded in the first frame of the fla, but this could be loaded dynamically off course), which sets a variable, loops 5 times, waits for user input, manipulates the variable and traces some strings to the output window. Nothing fancy, but it's a demo.

    It uses only "internal" functions (functions that are built-in into the engine), except for the <waitKey> function, which is defined in the ScriptingApi object which I pass the engine. This function demonstrates how to pause a script and then continue it.

    Note that it could easily be ported to AS2 if anyone needed it in pre-Flash 9, except for some small details (the int and uint datatypes, mainly), and I'm not sure if it would be performant, but I don't think it would be a problem.

    Some feedback would be appreciated
    Attached Files Attached Files
    Last edited by Fall_X; 07-30-2006 at 09:41 PM. Reason: Update

  2. #2
    Shenanigans JimmyDinner's Avatar
    Join Date
    Mar 2003
    Location
    Vancouver
    Posts
    175
    It looks like it gets the job done well enough, but i'm pretty curious why you chose to use XML for it?

  3. #3
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Mainly becasue there's already a parser for xml, and it's pretty easy to itereate through. Any other format would have required me to tokenize a string and do more complex parsing, which would probably have been a bit slower than using a built-in parser that's using native code.

  4. #4
    Shenanigans JimmyDinner's Avatar
    Join Date
    Mar 2003
    Location
    Vancouver
    Posts
    175
    I can see how it'd be easy to iterate through and all, but I dont really agree that other methods are slower. All of the 'complex parsing' doesnt have to be done in the actual game at all - you could just have the complex looking script compiled into something simple like a tokenized string so all the hard stuff is already done and the game doesnt need to waste any time parsing it.

    If you did all the parsing/compiling beforehand you could have a lot more readability in the scripting language - which is probably my least favorite part of your engine. Maybe other people enjoy it, but theres something about scripting in XML that just seems so awkward and over complicated I think.

    Its still got some potential as is right now though, I just think maybe it would be easier to work with if the language were a bit more readable.

  5. #5
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Well, the whole point of this scripting language is that I wouldn't have to recompile things to add new functionality to my games.
    While I do agree that it's not very readable, usually the scripts would be pretty simple things like :
    <script>
    <moveNpc>NpcName<int>5</int><int>10</int></moveNpc>
    <moveNpc>OtherNpcName<int>15</int><int>20</int></moveNpc>
    <say>NpcName<str>Hello!</str></say>
    </script>

    So for things like that it would be very useable.

    One option would be to create a more readable format, and "compile" that to this xml-format using a seperate tool, or server-side when you're loading the scripts from a server (using php or asp), or "just in time" in the scripting engine. I'm not sure if it would be worth doing, especially since I have little experience tokenizing strings etc.

    If someone wants to help doing that, great

  6. #6
    Shenanigans JimmyDinner's Avatar
    Join Date
    Mar 2003
    Location
    Vancouver
    Posts
    175
    I use a string based scripting system for my recent games, so I definitely agree with you on the benefits of having something like this. I can also say that having the script precompiled was definitely worth it, in my case anyways. Having a simple readable language compiled into a smaller cryptic format let other people make scripted levels without having any sort of programming experience, and at the same time performance didnt have to suffer. If its just going to be you using the language though, it might not be worth if (as long as you're comfortable using your own language), but if unexperienced people are going to be designing stuff too then it might be a good idea.

  7. #7
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Huge update!

    I reworked a large part of the code :

    - I now have variable scope (meaning a <then>, <else>, <loop> or <code> block always has it's own scope, with variabkle inheritance from the containing scope)
    - It is now possible to pause the script from anywhere - so even a function called in an <if>-statement can pause the script, which is pretty cool
    - Functions! That's right, you can now write your own functions in the scripting language, complete with parameters and a return-value - check the example in the zip.

    Now, variables and scripted functions will be removed after the script has been executed, so next up is a way to specify global variables and functions.

    The zip in the first post has been updated.


    Edit : Come on, I'd like some people to test this or at least tell me what they think. I could just as well keep this for me, but I figured it would be useful to others as well. Since it's AS3, it's obvious that not many people will be needing it yet, but I think it's still pretty cool, and I can tell you it hasn't been easy to make this. Just give it a go

    Just to spark some interest, here's the example script included in the zip :

    Code:
    <script>
    	<function name="checkInput">
    		<parameter name="cnt" />
    		<parameter name="var" />
    		<code>
    			<trace><space/></trace>
    			<trace><concat>----- Iteration<space /><get>cnt</get>/5:</concat></trace>
    			<trace>Press a key to add 5.</trace>
    			<waitKey />
    			<set>var<add><get>var</get><int>5</int></add></set>
    			<if>
    				<compare><get>var</get>&lt;<int>25</int></compare>
    				<then>
    					<trace>It is now less than 25</trace>
    				</then>
    				<else>
    					<trace>It is now bigger than or equal to 25</trace>
    				</else>
    			</if>
    			<trace><concat>In fact, it is now :<space /><get>var</get>.</concat></trace>
    			<return><get>var</get></return>
    			<trace>This will never be executed</trace>
    		</code>
    	</function>
    	<trace>Hello world.</trace>
    	<set>testVar<int>10</int></set>
    	<trace><concat>testVar is :<space /><get>testVar</get>.</concat></trace>
    	<set>cnt<int>0</int></set>
    	<while>
    		<compare><get>cnt</get>&lt;<int>5</int></compare>
    		<loop>
    			<set>cnt<add><get>cnt</get><int>1</int></add></set>
    			<set>testVar<checkInput><get>cnt</get><get>testVar</get></checkInput></set>
    		</loop>
    	</while>
    	<trace><space /></trace>
    	<trace>--- The End ---</trace>
    </script>
    It's also useful for non-game related things, for instance, a website where you need to do some transitions/animations - you could easily script them with this.
    Last edited by Fall_X; 07-30-2006 at 08:22 PM.

  8. #8
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    'nother update. Due to popular demand (well, erm, somebody did compalin about it), AS3 strict mode is now supported.

  9. #9
    Junior Member
    Join Date
    Dec 2003
    Posts
    4
    Hey, this is a really good idea, loading the AS code dynamically into swf.

    You mentioned, this can be done for pre Flash 9 with AS 2.0. Can you post a simple example that is done using AS 2.0. Or at least explain the concept...?

  10. #10
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Just take a look at the zip file, and more specifically at the file com/gamesquid/squidscript/ScriptingEngine.as - this would have to be translated to AS2. I can't post an example of it, as I have not ported it yet, and don't know if I will - that depends on whteher I'll ever need it myself (or if someone wants to donate me something to motivate me, lol).
    The main part of the work is the difference in the way AS2 and AS3 work with xml. All of that would have to be rewritten. It's probably not particularly hard, but just a bit tedious.

    I'm actually considering having a <class> tag now, allowing you to make classes and instantiating them all from within the scripting language. I don't think it would be worth it, but it might be a fun thing to do

  11. #11
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    The main part of the work is the difference in the way AS2 and AS3 work with xml.
    does as3 have better XML parsing(i mean faster)

  12. #12
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Yes - or at that's what I read somewhere Since most of AS3 is faster, I don't question it. It's also a very different way of working with xml (it's called E4X).

  13. #13
    Junior Member
    Join Date
    Nov 2013
    Posts
    1
    Hey, I know this is bringing up a very old topic, resurrecting the dead as some might say, but this engine seems to be exactly what I am looking for as a Dialog engine for my AS3 game. I am curious though if the OP or anyone else might be able to work with me on modifying it to suit my needs. I am adept at AS3, but quickly perusing the code I am somewhat at a loss for the features. It would be greatly appreciated.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center