Access Object Properties from Plug-in

For developers using the Construct 2 Javascript SDK

Post » Sat Jun 30, 2012 1:55 am

BTW, as Ahsely said, you should use debug console when you develop plugin. In firefox, you could use firebug.
B
97
S
22
G
177
Posts: 4,111
Reputation: 103,525

Post » Sun Jul 01, 2012 12:58 pm

@Ashley & @rexrainbow, I have been using firebug all along, but during the process of writing this plugin, it became clear to me how much I still don't understand about JavaScript in general, and the C2 implementation specifically. It has been quite a learning experience. :D

I believe I finally had a eureka moment yesterday, and it all started making a lot more sense. After re-reading all of these posts (for the hundredth time), I believe that I am not being clear as to what I am trying to accomplish.

Perhaps this will make it a bit more clear:
1. The constructor opens a new project.
2. They add a Sprite & Keyboard object to the layout.
3. They add my plugin (let's call it MyPlugin) to the layout.
4. In the event sheet, under the On start of layout condition, they add the definition action from my plugin (MyDefineAction). MyDefineAction contains three params: Object, Property, Value.
5. For Object, they select Sprite. (Using the AddObjectParam function.)
6. For Property, they select Sprite.Angle. (At this point I am using the AddAnyTypeParam function, but this just refers to the value, not the property index.)
7. For Value they enter 90.
8. They add a Keyboard-->On Space Pressed condition.
9. Under this condition, they add the MyPlugin.MyExecuteAction action.
10. They export the project. During the export, the MyDefineAction function in the run time adds all MyDefinitionAction actions to a hash table, which includes the Object reference, the property reference, and the value.
11. When Space is pressed, the property in the referenced object is changed to Value.

What I am looking for is a way at step 6 to capture the index of the property. Then at step 11, I would reference the object and property index to change its value. I can't predetermine what the property will be, so I need to use a reference passed from the edit time, rather than the hard coded property name.

To answer concerns about the index being unsuitable, the constructor will define an existing object and property at edit time. The index number won't change after export or when the project is run. If the plugin programmer modifies the properties in the future, it won't matter, because the property index would be determined dynamically at edit time, after the plugin has been added to the project.

I apologize for the wall of text, and also if you already understood what I was trying to accomplish. I just feel I am very close to getting this to work.

Thanks!
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Sun Jul 01, 2012 1:15 pm

I'm not sure I understand the purpose of this plugin. Why would you do your example instead of just a 'Sprite - set angle' action directly? What does it offer over the Function object even?

The only way you can do step 6 that I can think of is to create a giant combo box with a list of every property across all plugins that you can think of. Then you'd have a giant switch-case of the combo index to the actual property that needs to be set or retrieved. That will survive minification and object properties being reordered, but is a pretty lousy user experience. Your plugin idea is kind of against the grain of how C2 is designed.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sun Jul 01, 2012 1:46 pm

[Quote=ashley] Your plugin idea is kind of against the grain of how C2 is designed.[/QUOTE]
Understood. I will scrap this and try a different tact. Thanks for your patience.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Mon Aug 06, 2012 1:37 am

Just how do I open the chrome debugger for edittime.js files? I thought the C2 editor was a windows app. So it is possible to debug edittime using a debugger?

Sorry if this is a stupid question but how would I go about doing this?
B
14
S
4
G
4
Posts: 20
Reputation: 3,676

Post » Mon Aug 06, 2012 2:16 am

@seac, press F12 for the Chrome debugger
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Mon Aug 06, 2012 3:17 am

yeah am doing that. Thanks!
B
14
S
4
G
4
Posts: 20
Reputation: 3,676

Post » Mon Aug 06, 2012 3:29 am

um... edit time.

F12 does do anything as far as I can tell within C2 editor.
B
14
S
4
G
4
Posts: 20
Reputation: 3,676

Post » Mon Aug 06, 2012 3:38 am

Method names are minified?

Wouldn't it be better in ACE call's were not minified?

It would make dev of behaviors more straight forward. I think the impact to would be minimal to the run time.
B
14
S
4
G
4
Posts: 20
Reputation: 3,676

Post » Mon Aug 06, 2012 1:23 pm

There is no debugger in the editor, you can only debug the runtime in a browser. Editor scripts are also not minified. The ACE names just have to match what the runtime says. It's really not a big deal that it's minified, it doesn't break anything as long as you write your code carefully.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

PreviousNext

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests