[SOLVED - Feature already included](Custom Block Name) for [Actor]

ShivaFang

  • Posts: 248
I am a little confused by the inclusion of other actors Custom Blocks (not Global Custom Blocks) in the Custom section without any way to specify which actor/behaviour they are supposed to be performed on.

It seems to me that you need to add 'for [Actor]' to the Custom Blocks in order for them to work properly for other actors.  It would naturally default to 'for [Self]'

I recognize what I'm proposing here can also be handled by events, but blocks are more intuitive I think with this change :)

« Last Edit: May 12, 2012, 09:39:06 am by ShivaFang »
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

rob1221

  • *
  • Posts: 9471
Even better, don't show (non-global) custom blocks when the associated behaviors are not attached to the scene/actor.  They won't work anyway (assuming "self" is not added).

« Last Edit: May 10, 2012, 11:52:39 pm by rob1221 »

ShivaFang

  • Posts: 248
@Rob:  Since Custom Blocks are 'Methods/Functions' you should be able to call them on another actor that has the behaviour attached.  When looking at the 'code' version, they are public methods, which means they can be called by other classes/instances.

In short, if you can supply an actor that has the behaviour, it will work the same way as if that actor had called it on Self.  (Or scene, or whatever)

I just thought of a reason why this would be better than using a Custom Event.  With a Custom Block you can pass variables.  Deal [number] damage to [Actor] would be AMAZINGly simple with this feature.

« Last Edit: May 10, 2012, 07:39:05 pm by ShivaFang »
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

rob1221

  • *
  • Posts: 9471
I'm referring to the blocks that don't allow an actor input.  However, hiding the blocks under that situation might be confusing to developers who haven't worked with custom blocks, so your suggestion is more newbie-friendly.

Epic428

  • Posts: 1118
I might be misunderstanding this.  But can't you just add [actor] as a variable to the custom block and pass it in?

For example, suppose I had a damage control behavior attached to the scene. In one of my actors, say a bullet, I could have a behavior where in the "when colliding" section it would say "deal [n] damage to [actor].

In this case, [actor] would be added to the custom block just the same as [n] was. I'm not at my pc so I can't check, but is that not possible to do?

Anyway I have a feeling what you're asking for already exists and I guess without understanding what it is you're trying to do I wouldn't be able to determine if it does or doesn't.

Edit:   Isnt the difference between a global and non global custom block the fact that global is a static function?

« Last Edit: May 10, 2012, 08:04:40 pm by Epic428 »
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

rob1221

  • *
  • Posts: 9471
@Epic428 I think he's asking for the "self" input to be mandatory rather than optional like it currently is.  It would be more intuitive as well.

EDIT: fixed to say "self" rather than "actor" (they're not the same).

« Last Edit: May 10, 2012, 10:30:48 pm by rob1221 »

ShivaFang

  • Posts: 248
@Epic - yes you could do that, but that's not what I mean.
@Rob - is it currently possible to add an actor to the current Custom Blocks so stencyl knows which actor is doing it?  I'm not talking about adding an extra variable to a method, I'm talking about calling the methods that are already there, since they are public not private.

For example, in the project I'm making, I made some bubbles that float up and I created a custom block called 'shimmy' which allows them to shift from side to side (triggers once after a random number of seconds and then every second after to prevent the bubbles from acting in unison).

Now whenever I'm making a script, I ocassionally see 'Shimmy' in my 'Custom Blocks' - even when I'm not even dealing with an actor even remotely related to my bubbles.  Now, if I were doing this in Adobe Flash there would be no reason I couldn't do something like _BubbleInstance.Shimmy() in any other code in the game (lets say, a button).  However, since it does not allow me to specify what actor I am referring to, the blocks only refer to self, even though I don't have the behavior added to a button.

I think it would be a simple change, really.  Simply add 'on [Actor]' at the end of custom blocks (but not Global Custom Blocks) that defaults to self, and if you supply another actor it will trigger the same function on that actor if they have the behaviour.

Given that there is another thread asking for a way to tell on that pallette which are Custom and which are Global Custom, two suggestions can be 'killed' with one implementation 'stone'.  Custom Blocks would say 'on [Actor], Global Customs wouldn't (since they are 'static', and therefore part of the 'class' rather than applying to an instance)
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

Epic428

  • Posts: 1118
Ah ok I get it.

So instead of referencing a utility class (which is what global custom blocks are useful for) (ie - Math.random()) you'd like the non globals to reference the actor instance such as [bubble actor].shimmy().

That makes a lot of sense and would be a nice change to make.

Then you could have something like:

For each actor of type [bubble]
[bubble] Custom: Shimmy [n] pixels over [n] seconds


I guess the appenditure is debatable.    "[actor] Custom:" might be a nice way to indicate it.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

rob1221

  • *
  • Posts: 9471
Oh, you weren't aware that what you're asking for is already possible?  Just include %0 (self) in a custom block for an actor behavior.  Despite the name, it lets you choose any actor to call the custom block for.  I learned that from Abigayl's lagless actor tutorial http://www.kongregate.com/games/Abigayl/stencyl-2-0-advanced-tutorial-lagless-actors.

Epic428

  • Posts: 1118
But isn't that passing the actor in as a variable rather than calling the function attached to the specified actor?

Essentially, the suggestion is like having an event that accepts variables in the parameters.
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

rob1221

  • *
  • Posts: 9471
You don't have to use "self" anywhere inside the custom block wrapper.  In that way it's different than the other inputs.  Just set the actor (like any other block that defaults to "self"), and the custom block will be called only for that actor.

Sunflower

  • Posts: 591
Wasn't it, like, already made? O.o'

As Rob stated, you don't have to use block "Self" anywhere in Custom Block body, the system recognizes it itself. It's because this "Self" parameter (which is mandatory and appears every time a new Custom Block for Actor Behavior is made; you just need to add %0 to specification) from code point of view isn't just an argument, but the object calling itself.

So using the example from bullet hitting, it's not like:
System.say("Enhanced Health Pack", "DealDamage",  actorHit, 100);
But it's this:
actorHit.say("Enhanced Health Pack", "DealDamange", 100);

I've used it many times and it works (not to mention that it appears as such in code as well), so I guess that's discussing something already added. ^^'

ShivaFang

  • Posts: 248
Oh, you weren't aware that what you're asking for is already possible?  Just include %0 (self) in a custom block for an actor behavior.  Despite the name, it lets you choose any actor to call the custom block for.  I learned that from Abigayl's lagless actor tutorial http://www.kongregate.com/games/Abigayl/stencyl-2-0-advanced-tutorial-lagless-actors.

Right but this would require me to add the behaviour to the actor doing the calling, which is redundant when only the actor being called needs to run it.

This is really basic object-oriented programming, and it's a shame stencyl doesn't support it when it would be so easy to implement.

Quote
For each actor of type [bubble]
[bubble] Custom: Shimmy [n] pixels over [n] seconds

Yes!  Exactly!  you get it.

@Sunflower - yes, you can do that in code, but not with blocks.  Which is why this is so easy to implement, and doing it with blocks allows the behaviour to work on iOS too, presuming custom blocks are also public methods on iOS.
Justin "ShivaFang" White
Aquamentos Games - The origin of challenging Strategy and Role-Playing Flash gaming!
Visit our Developer Blog and Google+ Page!

rob1221

  • *
  • Posts: 9471
Quote
Right but this would require me to add the behaviour to the actor doing the calling, which is redundant when only the actor being called needs to run it.

Nope, you only need the behavior with the custom blocks attached to the actor that is being called.  You can even call the custom block from a scene (the tutorial I linked does that).

Sunflower

  • Posts: 591
Quote
This is really basic object-oriented programming, and it's a shame stencyl doesn't support it when it would be so easy to implement.
This statement is about half-right. This *is* basic OOP and easy to implement, but it's not a shame because Stencyl already *does* support it with DM! >.<

Quote
@Sunflower - yes, you can do that in code, but not with blocks.
The code I included there wasn't "the code you can write". It's "the code Stencyl makes for you so you don't have to worry about these technical things and I saw in Preview Code". That's how it's been already made to work: when making a Custom Block in Actor Behavior, the Self parameter is the actor calling the thing.

If you don't believe, check for yourself. Really, do it, I forbid you to claim that Stencyl doesn't support it until you check that!
For example, try with this "Shimmy" block or something. When you make a new non-global Custom Block in Actor Behavior, there's *always* a %0 "Self" parameter which cannot be deleted. If you happened to ignore it, you can go to Custom Block palette and find there the "Shimmy" block, and then "Edit Custom Block Details" to correct the specification (however, you cannot change the parameters themselves or the return type). So yes, if there isn't %0 in specification, include it. As in, "shimmy %1 pixels over %2 seconds for %0".

After that, make a button or something, and include there something like that:
Code: [Select]
for each [actor of type] [bubble]
  shimmy 10 pixels over 1 seconds for [actor of type]
Of course, it might be something else, but it shouldn't be in bubble behavior itself; the point of this example is to show that you can use one behavior's Custom blocks somewhere else without attaching it to Actor/scene using the block.

Or just check the tutorial rob linked you to.