Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Random scene

astronomical
Registered User
Quote
2018-09-16 16:37:52

Hi, I'm very new to CC and would like to ask, if I have say 10 different scenes made and a menu. If I click "Go!" on the menu for example, it then randomly goes to any of those 10 scenes made?

Sorry if this is stupid question.


j9907
Registered User
Quote
2018-09-16 16:50:21

No, not at all. You can specify what scene you want it to change to very easily. It's called "switch to scene"

Or do you want it to specifically go to a random one?


astronomical
Registered User
Quote
2018-09-16 17:38:32

Thanks for the reply, and I found the switch to scene but I'm looking for it to be random, just to switch up the game in lieu of any form of procedurally generated levels.


tim12345
Guest
Quote
2018-09-16 18:34:19

if you name your scenes "Scene1","Scene2","Scene3" ect...
and then when click enter this javascript...
var value = (Math.random() * (10 - 1)) + 1;
var round = Math.round(value);
var name = "Scene"+round;
ccbSwitchToScene(name);

that might work.


astronomical
Registered User
Quote
2018-09-16 18:46:08

Excellent, thanks Tim, I'm at work tonight but I'll be sure to give it a try tomorrow. Thanks for your help


behroz-khan
Registered User
Quote
2018-09-17 13:19:32

Hi @astronomical Here's non-scripted and easy method for you. But as you have just used tim's method so I am just telling you about it.

When clicked Do something:
Set random value
Every 1 millisecond do something:
Check if <variable name> is 1 do something:
Change scene to <first scene>
Check if <variable name> is 2 do something:
Change scene to <second scene>
and so on...


astronomical
Registered User
Quote
2018-09-18 00:16:26

First of all, thanks for your input.

Tim, I give that a try and at first I had a box with a "if clicked on action" then "execute javascript". Just added it without the scenes and it thrown up errors saying it couldn't find random scenes between 1 and 10. Great! so I made 10 scenes with different colour backgrounds to named "Scene1" up to 10, and now it does nothing haha. Nothing flags up in console and it just seems to not execute the JS.

Behroz-khan, thanks for your reply also, am incredibly new to this whole thing, I'm more of a music and design guy, so I've not played with variables. I have zero knowledge of this stuff. :(

Oh and I'm not sure if this makes any difference, but I'm using the Steam version of CC6 Pro


tim12345
Guest
Quote
2018-09-18 14:15:21

what?!? how can this be???!! the code... it was so perfect in my mind....

...

... LOOK AWAY FROM ME!!!!! i cannot stand the shame of failure!!!

you MUST send me more information... a detailed description... a screenshot.... heck even the .ccb file itself so i can fix it! I MUST MAKE THINGS RIGHT to restore my honor again!!!


just_in_case
Moderator
Quote
2018-09-18 14:44:12

@tim12345 There is no error in your piece of code....it should work exactly as you had thought...you are a good programmer...

@astronomical the problem is that you have different scenes with different backgrounds color... and it is a very old bug in coppercube when the scene is changed the background color remains same or change to default color...

so i would like to suggest you to try the code by @tim12345 with different scenes... without having different background color... i know you wanted to test out the code.. so instead of background color .. you can add diffrent scenenode.. for example use a sphere in scene 1.. and a soldier in scene 2.. and so on...

for the method proposed by @behroz khan... it will consume a lot of time... because you will have to add 10 times "if a variable has a value" and then 10x time another action to execute switch scene.. and if you want to do the same process in all the 10 scene then it will take 100x time to add those actions...

so i will recommend to use the method proposed by @tim12345


bigcatrik
Registered User
Quote
2018-09-18 19:59:02

For the three scenes "Cube," "Sphere," and "Plane" this code will randomly switch to one of them.


var myScenes = ["Cube", "Sphere", "Plane"]

var newScene = myScenes[Math.floor(Math.random() * myScenes.length)];

ccbSwitchToScene(newScene);



behroz-khan
Registered User
Quote
2018-09-22 09:16:42

Oh yeah @just-in-case i didn't thought of it but my method would only be easy when using a little amount of scenes like 5 or so.


Create reply:


Posted by: (you are not logged in)


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