SetTileAt code

00george

  • Posts: 161
Hi I trying to make a custom global code block but have been having some troubles. I have tried the code normaly and it works fine. So the problem has to be my custom block. Any help would be appreciated.
Code: [Select]
Behavior: Design_0_0_GenerateDungeon at line 39
Call to a possibly undefined method setTileAt.
        setTileAt(__row,__col,__layer,__tilesetid,__tileid);

Code: [Select]
package scripts
{
import flash.display.BlendMode;
import flash.events.*;
import flash.net.*;
import flash.filters.*;

import Box2DAS.Collision.*;
import Box2DAS.Collision.Shapes.*;
import Box2DAS.Common.*;
import Box2DAS.Dynamics.*;
import Box2DAS.Dynamics.Contacts.*;
import Box2DAS.Dynamics.Joints.*;

import stencyl.api.data.*;
import stencyl.api.engine.*;
import stencyl.api.engine.actor.*;
import stencyl.api.engine.behavior.*;
import stencyl.api.engine.bg.*;
import stencyl.api.engine.font.*;
import stencyl.api.engine.scene.*;
import stencyl.api.engine.sound.*;
import stencyl.api.engine.tile.*;
import stencyl.api.engine.utils.*;

import org.flixel.*;
import mochi.as3.*;
import flash.ui.Mouse;



public dynamic class Design_0_0_GenerateDungeon extends SceneScript
{
 
/* Params are:__row __col __layer __tilesetid __tileid */
public static function Create_Tile(__row:Number, __col:Number, __layer:Number, __tilesetid:Number, __tileid:Number):void
{
    setTileAt(__row, __col, __layer, __tilesetid, __tileid);
}

 
  override public function init():void
    {
     
    }        

public function Design_0_0_GenerateDungeon(ignore:*, scene:GameState)
{
super(scene);

}

override public function forwardMessage(msg:String):void
{

}
}
}

coleislazy

  • *
  • Posts: 2607
Since its a global custom block, it doesn't have a reference the the class containing setTileAt. If you want to use it in a global block, you'll have to pass a reference as an attribute of the "anything" type, in which you would place a code block containing the word "this". Then, in the global custom block, you would use call the setTileAt method on the reference. Something like:
Code: [Select]
__MyReferenceAttribute.setTileAt(blah, blah);

00george

  • Posts: 161
Im really sorry but im having trouble understanding what I need to do. What code do I need to add? Sorry im not much of a coder.

coleislazy

  • *
  • Posts: 2607
Its hard to explain without pictures, but your block will look something like:

create tile at row: [row] col: [col] layer: [layer] tilesetid: [tilesetid] tileid: [tileid] reference: [reference]

You already have the others down, but the "reference" attribute should be of the type "anything" when creating the block.

Now, when you fill the block in, drop a code block in "reference" containing only the word "this" (this refers to the current object, in this case a SceneScript or ActorScript). It will look like: [this]

In the code of your global custom block, instead of just using:
Code: [Select]
setTileAt(blah, blah, stuff);
you would do:
Code: [Select]
__reference.setTileAt(blah, blah, stuff);
Basically, a global custom block has no idea of the current context. It doesn't know what scene is loaded or what actors are active. You have to pass the current scene or actor calling the block in order for it to know where to find the desired method.

I hope that helps!

00george

  • Posts: 161
Thanks alot :), I have been trying to learn java lately and have always wondered what this ment.