Custom block

spinnerbox

  • Posts: 166
I just made new custom block and added one Number parameter, but I cannot see it available when using it in another behavior i.e I cannot pass number parameter to this custom block.

I followed this guide: http://www.stencyl.com/help/view/creating-custom-blocks/

I am still using Stencyl 2. What do I do wrong?



siddharth93

  • Posts: 125
You need to specify the design in Block Spec, for ex.
I want to make a function for finding the remainder,
I will need Block Field number1 and number2, number1 is the dividend while number2 is the divisor.
To use this function you will need to provide paramteres of these numbers, which can be done by using the Block spec field,
Find remainder when %0 id divided by %1
%0 and %1 are reference for block spec fields.



spinnerbox

  • Posts: 166
Such a complicated thing to do! I created custom global block and I replaced all local variables with game attributes and wen testing it it says: I cannot find method getGameAttribute() ????

Some of the output:

Behavior: Design_391_391_SceneHelper at line 43
Call to a possibly undefined method setGameAttribute.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(0), Math.floor(2))]));

Behavior: Design_391_391_SceneHelper at line 43
Call to a possibly undefined method getGameAttribute.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(0), Math.floor(2))]));

Behavior: Design_391_391_SceneHelper at line 43
Call to a possibly undefined method randomInt.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(0), Math.floor(2))]));

Behavior: Design_391_391_SceneHelper at line 48
Call to a possibly undefined method setGameAttribute.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(2), Math.floor(5))]));

Behavior: Design_391_391_SceneHelper at line 48
Call to a possibly undefined method getGameAttribute.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(2), Math.floor(5))]));

Behavior: Design_391_391_SceneHelper at line 48
Call to a possibly undefined method randomInt.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(2), Math.floor(5))]));

Behavior: Design_391_391_SceneHelper at line 53
Call to a possibly undefined method setGameAttribute.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(6), Math.floor(12))]));

Behavior: Design_391_391_SceneHelper at line 53
Call to a possibly undefined method getGameAttribute.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(6), Math.floor(12))]));

Behavior: Design_391_391_SceneHelper at line 53
Call to a possibly undefined method randomInt.
            setGameAttribute("deckType", Number((getGameAttribute("deckTypeList") as Array)[randomInt(Math.floor(6), Math.floor(12))]));

Photon

  • Posts: 2693
Can post the custom block or a snapshot of your configuration for said custom block?
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

rob1221

  • *
  • Posts: 9472
Many blocks don't work inside global custom blocks, so you usually want to use a normal custom block instead.

spinnerbox

  • Posts: 166
Well the point was code reusability. I wanted to create one custom block with one parameter and use it in two behaviors by just passing a parameter. My block part is very big and I use the same logic in two behaviors which is lot of duplicate code.
And @rob what do you mean many blocks doesn't work in global custom block?

Photon

  • Posts: 2693
What exactly are you trying to do? A potential solution is to include the %0 parameter in the custom block (if you are using an actor custom block.) This makes the custom block execute local to the actor in question. For instance, if your custom block accesses two attributes, specifying the "target" actor will touch the two attributes relative to that actor. If I'm not mistaken, the only stipulation then past that, obviously, is that the target actor have the corresponding behaviors.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

spinnerbox

  • Posts: 166
Your note is good. I have initialization code in the loading scene behavior, but also the same thing happens when I press reset button which has actor behavior, which in turn resets all data about the game to the initial game state. What should I do in such a case?

Photon

  • Posts: 2693
Code or behaviors. Post them.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

spinnerbox

  • Posts: 166
It doesn.'t matter. I am talking about same chunk of blocks in scene behavior and actor behavior. It is more about design than faulty code/block. And I removed global custom block. I don't use it, neither normal custom block. It breaks my game.

And to be specific, the initial scene sets order for each level for the cards. The same thing happens when I press reset button.
So my initial scene has a scene behavior which sets card order for each level.
But also my reset button which has an actor behavior does the same thing i.e sets order of cards foreach level.

 But yes whatever I think I should remove the same chunk of blocks from the reset button behavior.

siddharth93

  • Posts: 125
Code or behaviors. Post them.
Helping others is a tough job :/