Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Is this possible with coppercube/javascript?

Madrid22
Guest
Quote
2017-03-21 15:07:34

Hello,

I have some variables in the game like:
var near1 = 0;
var near2 = 1;
var near3 = 0;

etc...
which I use to let the system understand when I am near an object
( 0 = not in the object radius area
1 = in the object radius area ).

Now because I have like 30 variables like this, I don't want to copy paste the same code 30 times...

Is it possible to use wildcards?

I think something like this:

if (near* == 1) {
ccbSetSceneNodeProperty(overlay*,'Visible',true);
}
So in this case when I'm near the object 2, the overlay2 will be visible,
when i'm near the object 4, the overlay4 will be visible, etc...

If you need me to explain better what I want, please ask... I would really appreciate if someone will help.


niko
Moderator
Quote
2017-03-22 04:25:31

No, but you can do this using arrays. Similar to what you suggested. Somewhere in the beginning of your game, initialize the array with this:
var nearTester = new Array();


and set the content with this:

nearTester[1] = 1;
nearTester[2] = 0;


and , then you can test using

if (nearTester[1] == 1) ...



Madrid22
Guest
Quote
2017-03-22 12:01:52

Hi niko and thank you,
but wouldn't it be the same like now?
Because if I use arrays like you suggested, I will have to copy the code 30 times:
if (nearTester[1] == 1) ...
if (nearTester[2] == 1) ...
if (nearTester[3] == 1) ...
So it would not semplify it...
I'm looking for a better solution that would make me write the code only once, and even if I add other objects in the game, I don't need to add more code.


jaimezegpi
Registered User
Quote
2017-03-22 13:09:32

?????

You can cast all object in scene and get distance from player ( calculate hypotenuse ) and know this var... don't need make many code.. not more 6 lines ( i think )..




erik
Registered User
Quote
2017-03-22 13:13:18

You can use a loop and go through an array. Like this:

for (var i=0; i<nearTester.length; ++i)
{
if (nearTester[i] == 0)
doWhatYouneed();
}



Madrid22
Guest
Quote
2017-03-23 10:21:11

Thank you all!

Erik, I tried your way to (for loop and go through array) and it worked perfectly!

Thank you!!!


Create reply:


Posted by: (you are not logged in)


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