Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Calling parameters of behaviors in JS

moonchristmas
Registered User
Quote
2022-10-20 02:46:41

Sorry if the title is gibberish, I'm new to coding haha

I have two questions, one more specific and one really broad about how CC works.

The first is how I would go about changing the TimeNeeded parameter of the Follow a Path behavior. Right now I have a sphere following a looping path at a certain speed, and I'd like to modify that speed (which is currently defined by the TimeNeeded) when the sphere enters a proximity trigger (just a cube with no collision I placed in the path).

The second question is related, because I'm just not sure what the standards would be for referencing certain behavior features and action features that I can see in simple js. I've seen something about referencing a node's direct features with like $ThingName.Scale, but not how to say something like $ThingName.Behavior.Action.ActionParameter etc. If that's even possible in that sense.

I feel like I could use a lot of more powerful features without getting too complicated with the code if I could execute simple js functions while referencing more nuanced details of the behaviors, but I have no idea how to express those behaviors in js and I'm not sure where to begin looking in the documentation. Does every behavior and action property have a unique way to reference it in js?


Robo
Guest
Quote
2022-10-20 11:26:01

I haven't used the default looping system for ages so unsure as I use my own path following code. Perhaps its as simple as modifying the balls movement speed with node.movementSpeed....been a while since I used that method...

There are only a few things that can be changed during runtime of the default CC Actions & Behaviors like movement speed, and a few other thing for the Camera setup, most things are setup and fixed (unable to be changed at runtime).

Any downloadable Behavior or Action can be accessed though as you like - just lookup the variable name and change it. Yo can open it in NotePad++ or other software to view it.


moonchristmas
Registered User
Quote
2022-10-20 14:51:52

I guess that's my other very basic question that I haven't been able to figure out then--what exactly am I opening in notepad++? Do I need to be exporting a separate file from the engine that stores the js for my entire project? Do I have to just not use the behaviors/action visual scripting system at all if I want to work with them in js? All I ever see in the folder structure is the File.ccb and File.exe and when I try to open the ccb in notepad it's weird unreadable symbol nonsense, not js as far as I can tell.


Guest
Guest
Quote
2022-10-20 18:54:50

Remember the ball drop example I sent you, moon? I had a JS file in the folder. I called functions from that file using CC's behaviors and actions. It's just a text file with the JS extension. You can change the extension to txt and open it just like any other text file. To import your JS file into your ccb file, it must have the exact same name as your cbb. Game.ccb & Game.js, for example. If you want to keep all your code inside the CC editor, you do a Before First Draw behavior with the Execute Java Script action and copy & paste the code into it. Then when you publish your project you don't need the JS file. But yes you can use a JS file with CC's default behaviors and actions and even your own custom ones; however, you can't open a cbb file in a text editor.


moonchristmas
Registered User
Quote
2022-10-20 20:14:18

Oh ok thank you, that makes sense. I wasn't sure what the difference between executing js inside of CC was compared to the js file you had in the example that was there on its own, or really how CC knew to use it. So basically the js you had outside of the project is the equivalent of doing a Before First Draw js execution?

So going back over the test.js script you made, I guess what I'm more getting at is that I'm wondering if there are ways to get deeper into the behavior's functions with JS. For example, here I see you've made a variable spawner where you get the variable from the ccbGetSceneNodeFromName, then you further get the position of the spawner in the line below it. I'm just in the Coppercube Documentation looking at the list of "all existing functions" and it seems like it doesn't include a variety of functions I'm regularly using in the editor, like "on proximity do something" or "when clicked on this do something." Or am I just misunderstanding how these functions work?


Guest
Guest
Quote
2022-10-20 21:05:26

Yes the JS file outside is similar (perhaps not exactly) like the Before First Draw behavior. I believe the inbuilt behaviors and actions of CC are written in C++, but most if not all can be written in JS in your own custom behavior/actions using the JS API that comes with CC. The JS API is like a set of functions that can be used to translate code into C++ using JS. CC interprets these functions as C++ code. Behaviors/actions use multiple functions as well as other parts of JS to perform their instructed purposes. Basically there are no exact equivalents of CC's behaviors/actions in the JS API because they are made up of similar functions written in C++. For something like the On Proximity behavior you would write a code that tracks the distance between two points and performs an action when a set criteria is met. There are functions in the JS API that allows you to get key and mouse events exactly like how the When Clicked behavior works. I know this all may sound complex, but it's actually pretty simple once you get the needed understanding. Let me know if you need any more clarification.


Create reply:


Posted by: (you are not logged in)


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