Make code preview more useful

dripple

  • Posts: 748
It took me a while get into this, but now I get used to look into the source files generated to find the bug and look into my code blocks to fix it. I never checked the red line in my behavior *blush*

I never got the  idea of the code preview as it doesn't match either the blocks (order of the methods) or the final sources.

(Split up from this bug report: http://community.stencyl.com/index.php/topic,25248.0/topicseen.html)

« Last Edit: May 02, 2014, 04:27:54 am by captaincomic »
Sure, my games won't get better with all the new features of Stencyl.
But I do have more fun creating bad ones.


MayazCastle Keeper

captaincomic

  • *
  • Posts: 6109
It took me a while get into this, but now I get used to look into the source files generated to find the bug and look into my code blocks to fix it. I never checked the red line in my behavior *blush*
Yup, I do this too, but I think it's not very user-friendly that way.

Quote
I never got the  idea of the code preview as it doesn't match either the blocks (order of the methods) or the final sources.

Well, it matches the source except for whitespace, or do you mean even the code doesn't match somehow?

dripple

  • Posts: 748
Well, it matches the source except for whitespace, or do you mean even the code doesn't match somehow?
Oh no, don't get me wrong.
I wanted to say that the source code view doesn't reflect the blocks code in a way that one can see what he has done in the block mode. Look, there's an "when created"-event, but in the source, it's the init() function.  If I add an event "scene.onCollision", for example, I can't find any reference in the source.


Here's an example:

Two events:
- "when created", I renamed it to "cursor.Init"
- "always", I renamed it to "cursor.Update"

The blocks look like this: (btw. why aren't they are in the same order exported then they appear in the event list?)


... and the source code is this:
Code: [Select]
(import statements snipped)

class Design_136_136_CursorController extends ActorScript
{
    public function new(dummy:Int, actor:Actor, engine:Engine)
    {
        super(actor, engine);
        nameMap.set("Actor", "actor");
    }
    override public function init()
    {
        actor.makeAlwaysSimulate();
        addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
        {

            if (wrapper.enabled)
            {
                if ((actor.getX() < 48))
                {
                    actor.setX(48);
                    actor.setXVelocity(0);
                }

                if ((actor.getY() < 48))
                {
                    actor.setY(48);
                    actor.setYVelocity(0);
                }

                if (((actor.getX() + (actor.getWidth())) > 672))
                {
                    actor.setX((672 - (actor.getWidth())));
                    actor.setXVelocity(0);
                }

                if (((actor.getY() + (actor.getHeight())) > 432))
                {
                    actor.setY((432 - (actor.getHeight())));
                    actor.setYVelocity(0);
                }
            }
        });
    }
    override public function forwardMessage(msg:String)
{}}

If you have more complex behaviors, the order of the generated code is also different then the order of the events in event pane, which makes searching for your code more complicated

It takes a lot of time and understanding to find your own code here, as none of my identifiers (cursor.Init() or the systems identifier (always, when created) do appear.

I suggest at least:
- implement comments to reflect the events (insert event name and type)
- if possible, keep the order of the events code the same then in the event pane
Sure, my games won't get better with all the new features of Stencyl.
But I do have more fun creating bad ones.


MayazCastle Keeper

captaincomic

  • *
  • Posts: 6109
Ah, I see what you mean now.

 
I suggest at least:
- implement comments to reflect the events (insert event name and type)
- if possible, keep the order of the events code the same then in the event pane
The comments are a great idea, and maybe not too difficult to implement. About the order, I don't know if that's possible.

Another fancy way to make the code preview more useful, would be to have it side by side with the blocks, and when you hover the mouse over a block it highlights the code in the preview. That would be a lot harder to implement though.


dripple

  • Posts: 748
About the order, I don't know if that's possible.
I assume also that this is not working: I can have multiple Init-events spread all over the event list, maybe at the last position. So the source code generator must collect this snippets together into one single init() function. I assume the same for all other event types (that's how I would implement it)
Sure, my games won't get better with all the new features of Stencyl.
But I do have more fun creating bad ones.


MayazCastle Keeper

captaincomic

  • *
  • Posts: 6109
Okay, I added in comments for all events. Ideally they would take the name from the events pane, but at the moment I didn't figure out how to do that, so the comments just tell you what kind of event it is - still much better than nothing for now.

About the order, it seems to me that actually only the "when created", "custom import", "custom code" and "(global) custom block" are out of order, because the have to be in a specific place in the code. All events which register a listener are in order. The comments should make it easier now to find where the out-of-order events are in the code.