plugin virgin

For developers using the Construct 2 Javascript SDK

Post » Mon Mar 19, 2012 9:17 pm

Hi, i am creating first time plugin that will simply show a message alert with a string.

I created the plugin using the SDK template, i just changed the name and icon thats all, and also the settings like web, object etc..

I ran the project, when i make no reference to the lolo actions it works fine.

then i add a button and in its click event i add an action to use the alert action of lolo plugin, then i run the project and all i get is a blank grey screen and nothing works.

here is the zipped project file. I have placed the plugin folder "lolo" here as well, you can copy it to your construct 2 plugin folder.

http://uploading.com/files/9e5mfdfc/lolo.zip/

help appreciated.
B
7
S
1
Posts: 65
Reputation: 821

Post » Mon Mar 19, 2012 9:49 pm

Read the tutorial about Checking for errors in browsers it should help you to find the problem in your code.
Also read and follow the C2's SDK.

Be sure to post your files on dropbox rather than on advertising slow and tedious webhosts.

Finaly moving this topic for the "SDK" forum, more appropriate for help requests.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Mon Mar 19, 2012 9:58 pm

Do you have another plugin - i cannot open your C2-project because C2 claims missing the "Scoreoid" plugin.

Some suggestions after a short look in the runtime:
#) Why do you init the instance-variables (or object-variables (?)) in line 70 outside any function? I suppose line 65 or 53 are better places for the initiation.
#) When these vars belong to the object it's better to call them with the keyword "this" - when you declare them with the javascript keyword "var" you make them global for the whole website. In line 57/67 are outcommented examples from the developer.
#) @"blank grey screen and nothing works."
For javascript-development it's a good idea to use the Firefox-Addon "Firebug" in Firefox or with Chrome the built in "Chrome Developer Tools" - shortcut [CRTL]+[SHIFT]+[ I ] - there you should see details for most errors.
[edit]post above [/edit]

g, Joe7 Joe72012-03-19 22:07:27
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Tue Mar 20, 2012 1:59 am

i make changes to the plugin javascript files but in order to test if they work i have close and rerun construct 2. its a pain!! why cant construct just reload the updated/modifed .js files before previewing the game??

Anyway i somehow got this to work.. i deleted some of those VAR declarations...maybe?

Well one last thing on this thread, can someone help me with this function, itts placed in the common.js file and called from one of the actions, it works but the post function doesnt work:

[CODE]
function getGame()
{
$.post("http://www.apisite.com/api/getInfo", {api_key:"b9d57f3fbf2faa8d607ad2fc6178ab153cc08b48",game_id:"k4scvKUW3",response:"xml"},
   function(data){alert("Data Loaded: "+data);},"xml");
};
[/CODE]rafhelp2012-03-20 02:00:57
B
7
S
1
Posts: 65
Reputation: 821

Post » Tue Mar 20, 2012 2:25 am

[QUOTE=rafhelp] i make changes to the plugin javascript files but in order to test if they work i have close and rerun construct 2. its a pain!! why cant construct just reload the updated/modifed .js files before previewing the game??[/QUOTE]
See Developer Preview Mode!Ashley2012-03-20 02:26:09
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Mar 20, 2012 9:18 am

@rafhelp:
1) The file common.js has another task(it should contain scripts for runtime and edittime)- i think only few plugins use it.

If you need/want external scripts/libs you can do it this way:
Put your "global" functions in an seperate file "yourFileName.js" (placed in your pluginfolder)and make in edittime.js a dependency (- create a parameter by the return of the function GetPluginSettings()"): "dependency": "yourFileName.js"

2) new XMLHttpRequest();
To make browserindependet developing much easier this is probably a task for jQuery (ajax - jquery)
When you have a look at the ajax-Plugin or the ajaxPost-Plugin(=fork of ajax) you'll see how you can handle data with jQuery. Easier to read and recommended in the manual is jQuery.foo() instead of $.foo()

have fun, Joe7Joe72012-03-20 09:26:44
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Wed Mar 21, 2012 1:46 pm

you got to talk to me like a newbie to javascript. I have tried alot oan decided it may be too time consuming to learn this.

I creat a new file called myfunction.js and placed it in the same folder as runtime.js.

no how do i reference to it and actually call function to it in the Addaction section of the templates.

Also i tried XMLHTTPREQUEST i can never get it to work when i have to pass multiple form data.
B
7
S
1
Posts: 65
Reputation: 821

Post » Wed Mar 21, 2012 6:27 pm

[QUOTE=rafhelp] you got to talk to me like a newbie to javascript. I have tried alot oan decided it may be too time consuming to learn this. ...[/QUOTE]
@rafhelp
Yes, it really sounds as if you need more practice with basic JavaScript before you try to implement plugins.

Have a look at this page in the SDK manual for good advice on mastering JavaScript.

Good luck with your learning!Velojet2012-03-21 18:28:54
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Wed Mar 28, 2012 10:58 pm

for the external js file i have placed a function in it but i cant call it, what is the structure required for the externl js file and how do you call function sin that file after importing using jquery get script
B
7
S
1
Posts: 65
Reputation: 821


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests