Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Scripts don't work on android

oip
Registered User
Quote
2021-08-08 16:20:20

I wrote a simple script to change the width of the 2d overlayitem depending on health. When building for Windows, everything works fine, but when I build for android, the width does not change.

Here is the code that changes the width:



/*
<behavior jsname="behavior_warhp" description="Warrior HUD">
<property name="MaxHP" type="float" default="0.0" />
<property name="HP" type="float" default="0.0" />
<property name="RegHP" type="float" default="0.0" />
<property name="ObjHP" type="scenenode" />
<property name="TxtHP" type="scenenode" />
</behavior>
*/



behavior_warhp = function()
{
this.intervalRegen = 1000;
this.Once = false;
};



behavior_warhp.prototype.onAnimate = function(node, timeMs)
{

this.HP = ccbGetCopperCubeVariable("HP");


ccbSetSceneNodeProperty(this.ObjHP, 'Width (pixels)', (415 / this.MaxHP) * this.HP);

if (this.intervalRegen < timeMs)
{
if (this.HP < this.MaxHP)
{ this.HP = this.HP + this.RegHP; }

if (this.HP > this.MaxHP)
{ this.HP = this.MaxHP; }

this.intervalRegen = timeMs + 1000;
}

ccbSetCopperCubeVariable("HP", this.HP);

return true;
};


CopperCube Variable "HP" is set in another script at the beginning of the game


just_in_case
Moderator
Quote
2021-08-09 07:15:58

Will, look into this. My only advice to you is when you are creating scripts for android target, first test them on webGL if it is working there then chances are high that it will work on android as well, also some commands on android platforms are not available so there are some limitations when working with android device.

Anyways when I will reach to my desktop I will try this and will get back to you😇


DouweDabbe
Guest
Quote
2021-08-24 04:22:30

some remarks:

* there is no error message ?

* I guess HP stands for Horizontal Position ?

* as a behavior it runs every frame or when scene changes that may prove a bit heavy for android.

* the if statements don't need curly brackets here.

* the calculation better written like (415 / this.MaxHP * this.HP)
what ever the operator precedence, it makes no difference, this way you unify the result into 1 statement

* here ccbGetCopperCubeVariable("HP"); you are converting the result of var HP to string is it not ?
i think ccbGetCopperCubeVariable(HP); is more correct.

* you should define global variable HP at
- at scene level
- at start before first draw
- define name HP as variable, value = 0;
or
- if your game file is named YourGame.ccb and results in YourGame.exe or .apk then
- you can also define global var HP in file YourGame.js as var HP = 0;
other scripts may then apply ccbSetCoppecubeVaruiable("HP", 1080); statements.


just_in_case
Moderator
Quote
2021-08-24 08:22:34

@Oip Sorry, but I was unable to test the script, I was busy with my website neophyte.cf, and I recently installed windows again so I don't have jdk and android studio. And CC in not working correctly on Win 11.

@DouweDabbe
ccbGetCopperCubeVariable ("HP"); is the correct method, it will not work if you don't use the string parameters for the variable name.

Using curly brackets is best practice when you are working with if and else statements, especially when you are doing a lot of stuff in one single statement.

@oip I tested the script and found that you are using Absolute position for your 2D overlay, and in webGL changing of absolute position don't work.

instead of setting "Width (pixels)" in your script, use "Width (percent)" and it will change the size of your overlay on webGL target and maybe on android as well. Regardless of the position mode, you have for your overlay in the editor it will just work fine.

And as I mentioned above when, creating scripts for android Target, Do a test if they are working on WebGL or not if they a re working on webGL platform, then they will work on android as well most of the times.

hope that helped.



DouweDabbe
Guest
Quote
2021-08-30 09:00:21

i found that on android:

* case switch case statements dont work

and on all target platforms

* 2d overlays can be moved but not scaled


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