Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
reference to extension itself

ssatguru
Registered User
Quote
2024-11-28 18:13:12

@Niko
In webgl, from my extension I can pass reference to the extension itself as follows
In extension I do

ccbSetCopperCubeVariable("v1",this);

Then in action (javascript action) I can get the reference by

let r = ccbGetCopperCubeVariable("v1");

Now in my action, I can use "r" to access various extension properties and methods

Same doesn't work in windows.
Is there a way to do this in windows?


okeoke
Registered User
Quote
Yesterday

var ref;

behavior_huevyor = function() {
ref = this;
}



ssatguru
Registered User
Quote
Yesterday

@okeoke
Are you saying set a global variable and access that from Action javascript?
Anyways, I tried that but it doesn't work for windows or webgl.


okeoke
Registered User
Quote
Yesterday

Full behavior code:
// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
/*
<behavior jsname="behavior_Blyat" description="Blyat">
<property name="temp" type="int" default="2000" />
</behavior>
*/

var ref;

var behavior_Blyat = function () {
this.khuy = 'khuy, pizda, djigurda'
ref = this;
};

behavior_Blyat.prototype.onAnimate = function() {

}

Script code which runs every 500 ms:
print(ref.khuy);

Ccb demo:https://drive.google.com/file/d/...


ssatguru
Registered User
Quote
Today

@okeoke
You are right, it works,
Thanks for the demo, that helped.

I must have mistyped something previously when I was trying it myself

Now , this does not work for webgl though.
For webgl it seems you would have attach the global variable to "window".

So the proper solution would be

// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
/*
<behavior jsname="behavior_Blyat" description="Blyat">
<property name="temp" type="int" default="2000" />
</behavior>
*/

var ref;

var behavior_Blyat = function () {
this.khuy = 'khuy, pizda, djigurda';
if (ccbGetPlatform() == "webgl") {
window.ref = this;
}else{
ref = this;
}
};

behavior_Blyat.prototype.onAnimate = function() {

}



bob
Guest
Quote
Today

make a list of windows versus webgl games caseoh has played and prepare yourself for a reason why you shouldn't bother targeting webgl... don't overwork yourself, m8...


bob
Guest
Quote
Today

also listen to this song because I am feeling spicy:

https://www.youtube.com/watch?v=...

p.s. sadly ambiera doesn't have a pirate emoji...


bob
Guest
Quote
Today

let me say one last thing and I will leave you guys alone, niven on itch gets more playtime than all of us (jic, robbo, etc) here and he can't even make a proper interaction system. acclimate yourself to the times, friend.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact