Using typed code Haxe in Stencyl vs. Drag and Drop blocks [Answered]

Yerghaiz

  • Posts: 17
So, I have a question.  Everything I know about using the typed code in Stencyl, I learned from the process of putting in a code block, going to the code view, copy and pasting the code, and manipulating it accordingly.  Needless to say, I've learned a great deal :D.  But, I am at a point now where I hand type most of my code, and I'm assuming there is a shorter way to reference things than the drag-and-drop block's code, which I presume calls extra functions, due to it's nature.  For example:

Code: [Select]
if ((Engine.engine.getGameAttribute("Officers").length == 0))
            {
                Engine.engine.getGameAttribute("Officers").push(new Array<Dynamic>());
                Engine.engine.getGameAttribute("Officers")[Std.int(0)].push(("" + "Captain Braggart"));
                Engine.engine.getGameAttribute("Officers")[Std.int(0)].push(1);
                Engine.engine.getGameAttribute("Officers")[Std.int(0)].push(0);
             }

My question then is, is it possible to short hand?  Any help would be appreciated!

« Last Edit: August 13, 2015, 10:41:01 pm by Yerghaiz »

Justin

  • *
  • Posts: 4716
Not 100% sure what you're asking for, but you could make that shorter like this.

Code: [Select]
var officers = Engine.engine.getGameAttribute("Officers");

if(officers.length == 0)
{
  officers.push(["Captain Braggart", 1, 0]);
}

It's possible that could fail to compile because of Haxe's type system, in which case you might need to explicitly define types to let it compile.

Code: [Select]
var officers:Array<Dynamic> = Engine.engine.getGameAttribute("Officers");

if(officers.length == 0)
{
  var newOfficer:Array<Dynamic> = ["Captain Braggart", 1, 0];
  officers.push(newOfficer);
}

You can see what the code you originally posted is actually doing by viewing the engine source code at Stencyl/plaf/haxe/lib/stencyl/1,00. If you add that as a folder to sublime text or atom or another coding text editor, you can get an easy way to jump between files. (I can press ctrl + p in sublime text and type in "Engine" to bring up the source code for the Engine class.)
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

Yerghaiz

  • Posts: 17
That is EXACTLY what I needed to know!  Thank you good sir, for your very quick response.  I will now  go continue to try and spread the word that Stencyl is not terrible, as many people think  :P

Justin

  • *
  • Posts: 4716
Spread it far and wide. ;)
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

Yerghaiz

  • Posts: 17
I already do.  I publish on Kongregate, where Stencyl is considered a fail, and I love it when people ask me how long it took me to learn AS3 :D  I get to very happily reply that I didn't.  This is all Stencyl.  My wife and I saw what most people are producing with Stencyl and said to ourselves, "But this IDE can do so much more than this!".  And it has been an arduous road, and I still don't know how to do half of what I'd like to (not without some crazy long hand coding or a lot of drag and drop :P), but I see the potential that Stencyl has to help people go from knowing nothing about programming, to intermediate and even advanced levels of programming. 

I don't know if it's faux pas to link to games off site, but if it's not, I'd be more than happy to link my current WIP game for everyone to see.

Nevermind...found the place to do that :D

stefan

  • *
  • Posts: 2263
Please feel free to show them my QuickGuide video I did about Stencyl. You can find it on my website under the "Stencyl" page, located in the top with "here" (hyperlinked).

Cheers!

Yerghaiz

  • Posts: 17
Looks informative :D  I will definitely send new people that way.