Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
that's how you can setup custom health bar

mrandy
Registered User
Quote
2021-06-10 19:00:58

https://drive.google.com/file/d/1kdpB-ZJTLiEpH1DSOBscTt8ep0FTQCFo/view?usp=sharing



this is how you can setup a health bar in your game

for any question or any query feel free to ask


VP
Guest
Quote
2021-06-16 12:58:31

Maybe it's an error with my computer but it doesn't seem to work for me....

Healthbar doesn't move.
Bullets don't hit enemy.
Enemy can't hit player.
Player can walk through enemy.

...maybe the collision isn't working?

https://streamable.com/wqmzp6


monika_5
Registered User
Quote
2021-06-18 09:07:16

@VP

the health bar only decreases from one enemy which can't be killed. the first one you meet, I believe. the rest can be killed but do no damage to you.


VP
Guest
Quote
2021-06-18 09:49:15

Ah OK, cool. Thanks.

I'll download it again. I probably just killed the first enemy by instinct before he had chance to attack. lol.


DouweDabbe
Guest
Quote
2021-06-21 12:36:42

I can write the health to a 2d Overlay

but

I can not access it via a script in a Scripting window or
in action/behavior


var player = ccbGetSceneNodeFromName("clerk");
print("player="+player);

var myHealth = ccbGetSceneNodeProperty(pl;ayer, "@$%&player.health*&^%$@"):
print("myHealth="+myHealth);

error = : illegal charcter
or
error : reference error
or
object unknown



i think i tried every possible $ $ combination
any suggestions are welcome


DouweDabbe
Guest
Quote
2021-06-21 12:40:29

hash sign not printed there, buttt the looks like

=||=


VP
Guest
Quote
2021-06-21 16:35:06

I would imagine it's:

🔎︎



veganpete
Registered User
Quote
2021-06-21 16:35:47

🔎︎



just_in_case
Moderator
Quote
2021-06-21 16:51:51

@douwedabbe you are using a variable name as a property.

Don't use ccbGetSceneNodeProperty for the health variable.
Instead you need to use.

ccbGetCopperCubeVariable("hashtagclerk.health")

Also while accessing properties you did a typo in "player"
And wrote it "pl;ayer" and you are using so many symbols with the variable name thats why you are getting illegal character errors. However if you didn't had performed typo and used symbols it still would have throw you an error cause you were using variable as a property and it will throw an errror property doesn't exist.


To fix them simply replace your line with this

var myHealth = ccbGetCopperCubeVariable("hashtagclerk.health"):


Replace "hashtag" with hash symbol
And it should work fine.


DouweDabbe
Guest
Quote
2021-06-22 01:09:04

thanks

overlooked that

then corrected it for getting value out
but not when assigning creating another creazy bug

always take code back into proper editor with syntax highlighting


DouweDabbe
Guest
Quote
2022-05-23 16:33:54

How do I access thru some interchangable variable the health of a bunch of players?

"=||=someplayer.health"




fragment in for loop
...
var playerNode = ccbGetSceneNodeFromName(this.name);
var playerName = ccbGetSceneNodeProperty(playerNode, "Name");
var playerHealth = ccbGetCopperCubeVariable("=||="+playerName.toString()+".health"):
<-- error ccbGetCopperCubeVariable not js function
var playerHealth = ccbGetCopperCubeVariable("=||="+playerNode.toString()+".health"):
<-- error same message
...




sven
Registered User
Quote
2022-05-23 18:39:21

[quote]DouweDabbe wrote:
How do I access thru some interchangable variable the health of a bunch of players?

"=||=someplayer.health"



String.fromCharCode(35) you can replace with =||= if you want but not needed.


//this will be the name of variable.
var a = String.fromCharCode(35) + ccbGetSceneNodeProperty(this.node,"Name") + ".health";
//this will be the value of variable.
var b=ccbGetCopperCubeVariable(a);

make sure to print it .. so you see if name is correct and does value responds to it.
print( "Name " +a +" value " +b);



to scan a punch of nodes you can use numbers in names and use it like this..
i used to use AI1 AI2..and so on
And in for loop i just included name "AI"+i


OR scan folder..

var max = ccbGetSceneNodeChildCount(ccbGetSceneNodeFromName("FolderName"));
for (var i = 0; i < max; i++)
{
var t = ccbGetChildSceneNode(ccbGetSceneNodeFromName("FolderName"),i);
var current_name=ccbGetSceneNodeProperty(t,"Name");
}

((nodes must be in FolderName folder and will be scanned))
(i didnt test this script so may include errors but should give idea of it)


DouweDabbe
Guest
Quote
2022-05-25 03:32:34

Thank You Sven,
but still not working, I report it as a bug


sven
Registered User
Quote
2022-05-25 10:13:37

DouweDabbe wrote:
Thank You Sven,
but still not working, I report it as a bug


You have : instead of ; at the end of line.




ar playerHealth = ccbGetCopperCubeVariable("=||="+playerName.toString()+".health"):
<-- error ccbGetCopperCubeVariable not js function
var playerHealth = ccbGetCopperCubeVariable("=||="+playerNode.toString()+".health"):
<-- error same message


DouweDabbe
Guest
Quote
2022-05-25 16:22:05

no not true,
look better

https://www.ambiera.com/forum.php?t=10295


Create reply:


Posted by: (you are not logged in)


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