ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Programming and Scripting
forum topic indicator Trigger event on scene loaded
person icon
rednib
Registered User
Quote
2021-12-21 19:40:23

Hey,

I am new to CopperCube (i am experience with other engines though: Godot, Mono, BlitzMax etc.. also i am a software developer).

I wanted to run a script once as soon as a scene has been loaded. Is there a way to determine when a scene has been loaded via script? Similar to Godots "_ready()" function. I haven't found anything related to this in the documentation.

What i want to do is, i want to generate a mesh via script.
Therfore i would add a placeholder cube where i want the generated mesh to be positioned. As soon as the scene loads in the game, i would delete the cube via code and would generate my mesh. Fortunately Coppercube Javascript API provides easy to use functions for that: ccbAddMeshBufferVertex(), ccbAddMeshBufferIndex() etc..

person icon
just_in_case
Moderator
Quote
2021-12-22 04:05:23

You can either use an external script , that will execute when the scene loads. Or what you can do is you can execute your mesh generation script, by attaching it to an "execute javascript" action to the behavior "before first drawing do something" so that it will execute the script when the scene is loaded. If you don't want to use the execute script command then you can also convert your script into an action and can use it there with the first drawing behavior.

Having a javascript command for that can be a nice addition, but since there is already this before first drawing behavior, I never really needed that command.

Hope that helps????

person icon
rednib
Registered User
Quote
2021-12-22 13:28:51

just_in_case wrote:
You can either use an external script , that will execute when the scene loads...


How can this be archieved?

person icon
just_in_case
Moderator
Quote
2021-12-23 11:55:11

You can simply use an external javascript file with the same name as your project.
for example, if your CC project has the name "fight game.ccb" then you can use "fight game.js" as an external script file.

person icon
rednib
Registered User
Quote
2021-12-24 18:58:30

Ah OK good to know. And where do have to put the js file? Does this file gets automatically loaded and executed as soon as the game starts or do I have to call/start the script somewhere?

person icon
pmax
Registered User
Quote
2021-12-25 10:27:45

@rednib
Here is the link on how to use an external Javascript.
https://ambiera.com/coppercube/d...

PS: translation by DeepL


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






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