Can a plugin access other plugins?

Discussion and feedback on Construct 2

Post » Mon Nov 28, 2011 7:19 pm

Hello. First I'd like to say that I'm very impressed with this IDE and the community around it. So much so that it's inspired me to try and go deeper than the surface and understand the plugin system, with hopes of contributing positively to this community.

Sorry for the long post, but I'm unsure if I could explain what I'm trying to accomplish with less words.

This may sound odd, and please excuse me I am very new to all of this, but I was thinking about how I would like to interact/control some things in C2, and even develop a plugin or two. What I found myself planning for some of the plugins wasn't a "new" way of doing something, but more of a way to use what already exists. I'll try to explain.

I found it odd that I did not have full control over gravity for each object. I know gravity is a universal thing in the real world, but why can't I turn it off for one object if I want. Like, lets say I want a hovering ball that is also a physics object.
From what I found, I can't. So I came up with two options:
1. Try to counteract the gravity by an equally opposite impulse
2. Remove gravity all together and implement my own.

Obviously modifying one object is easier than all objects, so I tried the first option. Unfortunately I found it hard to get it "exact" so the ball kept moving just a little.
Option 2 seemed a better fit, so I proceeded to turn off all gravity and implement my own values for gravity (by using downward force) and just do it for each object I cared to have gravity "on". This provided exactly what I wanted, but having to add events in each time are tedious/annoying. I mean, I'm adding the same thing each time. Which I also had an issue with for the ball moving slowly, but fixed it by adding an event that turned "immovable" on, although it was already on, a quirk I am ok with.

I'm not a programmer or developer, though I have done a bit of both in my own "spare" time. I have extensively used a different game IDE, and although there is a lot of reasons I choose not to use it (biggest reason is the browser plugin requirement to play games in a browser), it did have one feature I am missing here. The ability to write a "script" and apply that to whatever object I choose.
The "behavior" system in C2 seems to have a similar ability, though it is quite a bit beyond my level of programming knowledge, I appreciate the challenge.

What I'm getting to is that in the "other" system I could access other scripts through one script. So if I wanted to modify a global variable, I could. Or if I wanted to apply a force to another object I could. And on and on.

What I've been looking for with C2 is a way to do something similar. What I've found so far, if I understand correctly, is that implementing a "scripting" option for the Event system is not possible because of the need to be cross compatible with any exporter that may be developed.
I have a question here. It seems to me that what people are looking for in a scripting system is a way to "write" what it is they are already doing in a more visual manner. So instead of a visual block that looks like an event, they would write:
event Gravity(){objectName.Impulse(forcePower, angle, imagePoint);}
or something similar. I understand this changes the way this IDE is meant to operate, and sounds to me like a considerable change for the developers, so...

This led me to want to attempt something similar on my own through the plugin system. I've spent a few days going over the SDK documentation, and reading over the comments in various plugins/behaviors. And although I don't completely understand all of it, I feel confident that I could figure it out and accomplish something. Problem is, I'm not sure what I want to do is even possible.

A couple examples:
1. A particle system.
Nothing crazy here, and nothing that I couldn't do through the event system, but if it was a plugin/behavior it would be way more usable, and others could also benefit.
All I need is to spawn X number of the same object in a definable area (x, y), apply some direction to these objects, and various other things like rotation, time to fad out, randomness, etc.
Everything I need for a particle system is already a part of C2, or in various plugins that come with the main package.
So to write a new plugin that already does what is available seems kind of dumb to me. Which leads me to my question: Can a plugin access other plugins?

2. Custom Gravity
Already explained above for why I would want to do this. The behavior would allow for access to the variables that dictate gravity and direction of gravity on a per object basis. Seems to me that I'd need two parts to this. One that set the variables on a global level, to be applied to an invisible object in the layout, and one that would be applied to the objects you wanted affected and took those variables. So the "creator" object type would be available to the "implementer" object type through a drop down list. Multiple of each would be possible for any object. Again, this is just accessing/passing info already available through the IDE and/or the physics plugin.

3. Scripting
All of these thoughts led me to think that I could do all of these things through a scripting method, if I only had that option. So why not try to build a plugin that allowed a way to do this through a weak scripting language that I could design? Several possible options on how this would work, but I could not find any way to access other, already present, actions in C2. As well as a way to have a "popup" so that you could input a larger amount of text than would be available in the little side bar text field.


Anyways... I'm pretty sure that if you made it through all that you get what I would like to accomplish. Before I spent more time looking for answers that may not exist, I thought I'd give it a shot on the forums.

Again, sorry for the long post. Thank you for taking the time to help me find some answers.

-Cym
B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Mon Nov 28, 2011 7:56 pm

Hey, welcome to the forums!

[QUOTE=cymrix]2. Remove gravity all together and implement my own.[/quote]
This is the best way to go. As you note it's a pain to set gravity for each and every object you want to affect, but we're hoping to introduce the Families (object grouping) system soon which will make this much easier - you'll be able to apply the gravity to a group of objects at once rather than having to re-do it for each object.

[quote]What I'm getting to is that in the "other" system I could access other scripts through one script. So if I wanted to modify a global variable, I could. Or if I wanted to apply a force to another object I could. And on and on.[/quote]
You can do this in the plugin/behavior SDK. Javascript doesn't employ any encapsulation (e.g. private variables or functions) so by its very nature you can edit anything in the runtime at any time from a plugin. Of course, you have to make sure you do it in such a way that it doesn't break the runtime - if you have any specific questions about this I'd be happy to help.

p.s. what was the "other" system? We don't censor mention of competitors here, because we're confident Construct 2 is the best.

[quote]What I've been looking for with C2 is a way to do something similar. What I've found so far, if I understand correctly, is that implementing a "scripting" option for the Event system is not possible because of the need to be cross compatible with any exporter that may be developed.[/quote]
Implementing scripts in Construct has been something that's been regularly discussed since Construct Classic (released 2007). We've never been keen on the idea: we want Construct 2 to be an event-based tool only, so we can focus all our energies on to making a great event system, rather than a half-baked event system which you're supposed to ignore in favour of script to do anything serious.

Adding script via a third party plugin currently isn't actually really possible - plugins can't extend the editor at the moment, so the only way to input scripts is via text objects or loading external files, which is probably more hassle than it's worth. And as I said we're not keen on the idea anyway. And as you note, it creates really difficult porting problems if we come to support other platforms further down the line - anyone using a script which is not ported to another exporter will not be able to port their game. I'd also advise against inventing your own scripting language. It's really complicated and hard, and I think inline snippets of javascript would be more useful than some unknown brand new language. And inline snippets of javascript are not far off the SDK, and the SDK makes plugins and behaviors which work really nicely with the editor, rather than random bits of script across your game.

If you want to design your own language as a hobby project that's cool, but I'm speaking more from a practical point of view (what we really want to be in the editor).

[quote]1. A particle system.[/quote]
We have an official particle plugin planned (it's the kind of thing very well suited to the plugin system). However if you want to try making your own, well, we can't complain if people are doing our work for us :)

Hope that covers everything, I would encourage you to have a play with the SDK, it's got documentation which should help you get going too! All the official plugins and behaviors are written in javascript in the SDK too, and you can find them in the install directory (exporters\html5\plugins and exporters\html5\behaviors) - you might find it interesting to see how all the official plugins and behaviors implement their features in javascript.Ashley2011-11-28 20:01:34
Scirra Founder
B
358
S
214
G
72
Posts: 22,946
Reputation: 178,333

Post » Mon Nov 28, 2011 8:43 pm

[QUOTE=Ashley] Hey, welcome to the forums![/quote]
Thank you, it's been a few years since I've hit up any forums, I'm really intrigued by your IDE.




[quote]p.s. what was the "other" system? We don't censor mention of competitors here, because we're confident Construct 2 is the best.[/quote]
Good to know, I wasn't sure and didn't want to make anyone mad. The IDE I'm referring to here is called "Unity 3D".




[quote]You can do this in the plugin/behavior SDK. Javascript doesn't employ any encapsulation (e.g. private variables or functions) so by its very nature you can edit anything in the runtime at any time from a plugin.[/quote]
Cool! I'll do a little research on accessing other variables through javascript, this is very interesting to me. Do you know of any plugins that use this, as an example?




[quote]We've never been keen on the idea: we want Construct 2 to be an event-based tool only, so we can focus all our energies on to making a great event system, rather than a half-baked event system which you're supposed to ignore in favour of script to do anything serious.[/quote]
I had a feeling this was the case, and I must say, your implementation of an event system is the best I've ever seen, it was the original reason I stuck around to check out C2.
I think that my issue isn't the event system, I really like it. What I want to be able to do is put events on objects directly. So that each instance of an object operates independent of another. Which, may be possible, and maybe my lack of understanding is to blame here.
When I put more than one instance of an object and then later want to modify that object it seems that all instances of that object are subject to the same command, and as far as I can tell, you can't pick one specific object through the event system (though you can pick them and modify them individually through the layout). Also if I could "reuse" these same group of events to be applied to other objects, it would increase productivity (this may be relative to the "family" thing you mentioned, which I would like to know more about).
This is what first led me to want to develop plugins as I've stated. Because, if I've understood the system correctly, when you have a random command (like rotate random degrees) as a behavior, every time an instance of that object is created it gets a new random number, but if done through the event system is gets one random number and applies it to all instances of the same object? Maybe I'm missing something?




[quote]Adding script via a third party plugin currently isn't actually really possible[/quote]
Again, my lack of knowledge/skill may be the issue here, but I was thinking more of passing strings as variables to the runtime and doing stuff with it there. The "scripting language" part would be the conversion from Forward 100 to "whatever makes something move forward", i guess it'd be with a lot of functions, etc, and is a huge endeavor. I think the "ZigZag" plugin does something similar, though I've yet to fully read through his code.
I respect your goals of C2, and would opt not to work toward things you guys feel circumvent what you are trying to accomplish, and if something like this falls into that category I would not attempt it.
Mostly it seems this is relative to the "if i could apply events at the object level" thing I was saying above. Cause this is what I'm really trying to accomplish.




[quote]We have an official particle plugin planned[/quote]
Cool :) I'd opt to not do one on my own then and focus on things that you guys are not working on. We'd get more accomplished that way :D And, of course, I'm still a long way off from doing something that complicated, IMO.




Thanks for the quick reply. If you have the time/patience to clue me in a little more I'd appreciate it.cymrix2011-11-28 20:47:35
B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Mon Nov 28, 2011 9:57 pm

[quote][quote]You can do this in the plugin/behavior SDK. Javascript doesn't employ any encapsulation (e.g. private variables or functions) so by its very nature you can edit anything in the runtime at any time from a plugin.[/quote]
Cool! I'll do a little research on accessing other variables through javascript, this is very interesting to me. Do you know of any plugins that use this, as an example?[/quote]
I can't think of any good examples, actually - it's not actually normally necessary to do this. But it's possible in case you really need to. I'd say read through the SDK docs, there's guides on how to access the full list of instances and such.

[quote]When I put more than one instance of an object and then later want to modify that object it seems that all instances of that object are subject to the same command, and as far as I can tell, you can't pick one specific object through the event system[/quote]
That's not true - it would be very difficult to design decent games if the event system didn't let you do that! The conditions in events act as filters to pick the instances you want to affect. For example the condition "Sprite X < 100" picks all individual instances to the left of X=100. If you then have an action 'Destroy Sprite', for example, only those picked sprites get destroyed, and the others are not affected. So the way events work actually is fundamentally based on picking individual instances of objects and running actions on them.

TBH designing plugins when you're not familiar with the way events work will be tough - I'd spend some time getting to know how C2 works first, then it will be much clearer what plugins are doing in their code.
Scirra Founder
B
358
S
214
G
72
Posts: 22,946
Reputation: 178,333

Post » Mon Nov 28, 2011 10:32 pm

Hmmm, either I am missing something or we are talking about two different things. When I use the event system to select an object, I only get a list of the original object types, not the instances of them. As well as in the layout I do not see any unique identifier for the instances.

I have made a test project. All i did was create a sprite, then make two instances of that sprite. I have two events. One waits 5 seconds and then destroys the sprite. The other moves the sprite 30 pixels at 45 degrees. When ran, after 5 seconds the original sprite is destroyed and so are the two instances of that object. If you hit spacebar before the 5 seconds is up it will move all the sprites 30 pixels.

https://www.sugarsync.com/pf/D743182_344420_8626501

I really do hope that I am just missing something.

Now, I have noticed that if your event is more of a condition like "if collision with bullet, then destroy" it will only destroy the one object that the condition was true for.
B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Mon Nov 28, 2011 10:39 pm

I guess you're just not used to C2. One of the rules of the event system is if an object is not referenced in any conditions, the action affects all of the instances. So since the 'start of layout' event does not use any Sprite conditions, the Destroy action applies to all the instances.

If you don't want the action to affect all the instances, you add a condition to pick which instances you want it to affect, e.g 'Mouse is over Sprite'.

Does that make sense?
Scirra Founder
B
358
S
214
G
72
Posts: 22,946
Reputation: 178,333

Post » Mon Nov 28, 2011 11:00 pm

I understand. I have not done a good job of explaining myself, but this is as I had come to understand it before my forum post, and the reason for my initial question.

so then, with the current system, what I'm looking for is an "on creation" method for an instance. Does this exist? So far I only know of adding behaviors to accomplish this.
B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Mon Nov 28, 2011 11:21 pm

well, i don't know if it's the best way to do it, but I've been testing a few things that would allow independent instance based behavior, without using behaviors. So far the best options seems to be the "over another object" option. Though I'm still interested if anyone else has a better method.

Thanks for the patience.

B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Tue Nov 29, 2011 12:13 am

You just have to dig around in the conditions. As it is there are several different ways to pick an instance.
First off when an object is created, either by the system, or spawned by another object, it is automatically placed into the selected object list, or picked if you prefer.
You can also pick via other methods such as on collision, x,y, opacity, etc.
Then there are other more specific methods such as the instances variable, its uid, or "pick nth", an index of the instances of that existing object.

Keep in mind the the selected object list is kept for the top tier event, and sub-events directly connected under it.
Second tier sub-events may loose picking depending on how you reference the initially picked object.

For practice, I would suggest assigning some Boolean values to the instances variable when it is created.

-+On mouse left clicked
-> system create sprite
-->sprite set instance variable sprite.("on") to 1

-+On mouse right clicked
-> system create sprite
-->sprite set instance variable sprite.("on") to 2

You can then do a comparison for the instance variable. If the value = 1 do this, 2 do something else.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Nov 29, 2011 2:27 am

:) I had been on this track while I was away from the forums. Thank you for the insight, it's good to know I was heading in the right direction. I've been creating instance variables and then putting the spawn values of whatever I've wanted to modify in them, and since they are relative to the instance it's been working. Would be nice to just be able to modify the size of an instance sprite without having to first pull the width and height of the instance as it's created and assign that to two variables, then use those variables as the relation to what I want the width and height to be, but I'll get over it :)

As an example of what I was trying to accomplish when I started this whole train of thought the other day, here is a test/model:
https://www.sugarsync.com/pf/D743182_344420_8627095
Enter loads the gun, space fires it.

Here I wanted steam to be created during the canister ejection, like it was depressurizing. Which meant creating a "particle" like effect. After I started it I realized that each "particle" was being affected the same, which led me to this forum post. Now, as you can see if you run it, when the canister is ejected each particle acts on it's own. Looking over the events that make that possible it's not as bad as I thought it would be, but if I wanted to copy/past this same set of events to another object I couldn't. I understand families are coming and it'll be interesting to see what that is all about.

I think my lack of knowledge on how javascript works is partly to blame here, and the new way of accomplishing things with C2 vs what I'm used to is the other part. I'm learning though, and hopefully someday I'll be able to help out on the forums here as you both have so graciously helped me.

Thanks again for the time and effort :)
cymrix2011-11-29 02:41:55
B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Next

Return to Construct 2 General

Who is online

Users browsing this forum: shinichild, veeru5656 and 10 guests