Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Execute a JavaScript-File

agbdev
Registered User
Quote
2021-04-04 20:37:33

Hey ho! : D
I have a small but nice question, namely is it possible to give a SceneNode a JavaScript behavior in CopperCube which executes a script on my PC or in the project folder where my game is located or is there. an extension that does exactly that? Because I find it annoying to always have to copy the scripts into CopperCube (I write them in VS code because it's much easier there). So I ask if there isn't a better and easier way :D


just_in_case
Moderator
Quote
2021-04-05 06:52:13

you can simply use any script file with the same name as of your project within the same directory of your project and Coppercube will automatically use it.

for example if you have project named as "Fps.ccb" then you can create a javascript file "Fps.js" in the same directory and whatever code you write in that js file will automatically used by your coppercube project.



agbdev
Registered User
Quote
2021-04-05 12:14:04

Thank you for the help
Now it's easier to use xD but unfortunately I can't use it for everything because I have a lot of different scripts that each have a specific task and some of them have to be executed when I press a 2D button, for example, and as far as I know there are no events in the JavaScript API for this.


just_in_case
Moderator
Quote
2021-04-05 14:51:07

you need to convert your script into actions for that or you can use mouse events within your script.
you can get the current mouse position and the 2D button position and can compare both of them and if mouse position is over the 2D overlay button and the mouse is down then execute the function through your script.
Or simply save it as action in the extensions directory and then you can execute it within the editor.

if that helps ..


smnmhmdy
Registered User
Quote
2021-04-05 17:47:45

You can define your functions inside of the script file and just call them using execute javascript action when the user clicks on the 2d overlay.
For example you can have this function in your script file:
fTest = function(){
print("Hello Friend");
}

and call it when the user clicks on the 2d overlay:
fTest();



Douwe Dabbe
Guest
Quote
2021-04-08 15:21:13

I want to know if we can "load" / "require" etc.
other javascript files from within:

* a coppercube action_script
* a coppercube behavior_script
or
* a coppercube library script

Also you / we can not use Coppercube datatypes and functions from within a coppercube Library file withhout "loading or linking" the irrlight definitions into that library.


smnmhmdy
Registered User
Quote
2021-04-08 15:38:38

require is from nodejs and as far as I know CC uses pure javascript with no framework, and javascript doesn't support any kind of external file loading mechanism (AFAIK). Although you can load an external file and use eval(), but it's infamous for being unsecure, so you can make your own choice whether or not to use it.
Also what do you mean by "coppercube library script"?


DouweDabbe
Guest
Quote
2021-04-10 01:41:53

myGame.ccb can have a library script file in myGame.js

here i can define datatypes and objects and functions with a global scope to my entire game (not just a scene).

I am thinking here at:
data types = sets, dictionary, linked lists, heaps, que's

I want to use it to define a graph datatype so I can implement some route finding



I must compliment you with that procedural environment with A* routefinding attached to it


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (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