How to return something from an extension

wedg3

  • Posts: 3
Hello,

     I try something easy as returning a number from and extension. I don't see any newbie starting with extension. I try to read other code but I really don't see what I have done bad. I know I can do it easy with other methode... but I need this to start something bigger. I normaly code in C and C++ for microcontroler not really this kind of stuff. I really need the basic. I code some stuff, import lib etc.. but that part isn't clear. thanks for you help

 First I do the code in blocks.xml
<palette>
   <block tag="return" spec="Print" code="Test.print();" type="normal" color="green" returns="number"></block>
</palette>

code in Test.hx

class Test
{
   public static function print():Float
   {
       var x : Float;
      x = 2;
      return x ;
   }
}

rob1221

  • *
  • Posts: 9470
You might have to set x to 2 on the same line but I'm not sure.  Other than that I don't know what else might be wrong.  There should be more information in your Stencyl logs.

mdotedot

  • Posts: 1653
What is the error?

My guess is the ; after the Test.print() 
Do a View Code and check out the code that is generated.

Code: [Select]
trace(""+Test.print(););   this is probably what it generates!

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

wedg3

  • Posts: 3
Thanks for the help ! As I say, it's really a newbie kind of error. If you look at my code for the blocks.xml. After the Test.print() you have a " ; "  when you run and action block, you need it because it's normaly the end of the line code.  When you return something as a number and ' Draw' it directly in a drawing event, you need to remove it or you a and unexpected error.  The test folder to start with have this " ; " and I doesn't know that code="" integrally write the code in my event.

   g.drawString("" + Test.print() ; , 10, 10); (code = "Test.print() ;" )
   g.drawString("" + Test.print(), 10, 10);(code = "Test.print() " )