ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator Countdown Time in CopperCube
person icon
okeoke
Registered User
Quote
2023-09-16 20:47:18

Hi Dynamogames,

A couple of ways how you can do that:
1. If you're using regular on proximity behavior attached to the object you mention, you can write current time to variable, and then on proximity action read it from the variable and write it to disk or store some other way;

behavior_CountDownTimer.prototype.onAnimate = function (node, timeMs) {
if (!this.lastTime) {
this.lastTime = timeMs;
return;
}

if (this.active) {
var delta = timeMs - this.lastTime;
this.lastTime = timeMs;
if (delta > 200) delta = 200;

this.timerMs -= delta;
if (this.timerMs <= 0) this.timerMs = 0;

var date = new Date(this.timerMs);
// write time to variable
ccbSetCopperCubeVariable('current_timer_value', date.getTime());

var mins = date.getMinutes();
var secs = date.getSeconds();
var text = this.textPrefix + strPadLeft(mins, '0', 2) + ':' + strPadLeft(secs, '0', 2); + '\r\n';

ccbSetSceneNodeProperty(node, 'Text', text);

if (this.timerMs <= 0) {
this.active = false;
ccbInvokeAction(this.actionOnRunOut);
}
}
}

Then on proximity you read 'current_timer_value' variable value.

2. Option two - check distance between player and the object inside timer behavior and save the value if it gets lower than the threshold.

person icon
dynamogames
Registered User
Quote
2023-09-16 21:15:41

Thanks @okeoke, I'm still trying to implement it, currently what I did was that I added the SetCopperCubeVariable line of code to the behaviour and then I set current_timer_value"

person icon
dynamogames
Registered User
Quote
2023-09-16 21:19:45

Then I set "current_timer_value" to a variable called "best_time" and then I save the variable "best_time" and I also added a behaviour "Before First drawing do something" such that the "best_time" variable loads every 100Ms. I also added a 2D overlay that displays the best_time variable ($best_time$).
I am not sure but would this work?

person icon
dynamogames
Registered User
Quote
2023-09-16 21:20:54

I set current _timer_value to best_time on proximity to the object

person icon
okeoke
Registered User
Quote
2023-09-16 21:29:06

If I understood you correctly, yes it should work, but there are some details:

before first draw you read best_time variable from disk. Than as soon as on proximity trigger is triggered you compare best_time to current_timer_value. If current_time_value is less than bet_time, you rewrite best_time variable and write it to disk.

Also you can't just $best_time$ since it's saved as integer. You can check the existing behavior for formating:

var mins = date.getMinutes();
var secs = date.getSeconds();
var text = this.textPrefix + strPadLeft(mins, '0', 2) + ':' + strPadLeft(secs, '0', 2); + '\r\n';


person icon
dynamogames
Registered User
Quote
2023-09-16 21:55:50

@okeoke currently I tried what you did but it's not working, the "best_time" variable just shows 0 and I think for some reason CopperCube is not reading the current _timer_value variable so the best_time variable can't work properly. I noticed this because I created a 2D overlay to display current_timer_value but it's not displaying any number.
I'll be glad to send the ccb file for you to inspect if you don't mind.

person icon
dynamogames
Registered User
Quote
2023-09-16 22:04:45

When I tested the game, I also noticed an error, "Script Reference Error: date is not defined", this might be the reason there is currently an issue.

person icon
okeoke
Registered User
Quote
2023-09-17 06:32:48

Yes, you're right. I forgot how this extension works.

Please find another example here, I've updated the script and tried to comment all new lines, so it's clear what they do:
https://drive.google.com/file/d/...

Remember to delete behavior_CountDownTimer.js from extension folder, before opening the .ccb file, or behavior will not be overwritten.

Also let me know if you have any questions.

person icon
dynamogames
Registered User
Quote
2023-09-17 20:20:02

Thanks @okeoke, I've been able to set everything up but at first I didn't get how the best time value worked or how is it gotten. I was expecting the best time value to be in the format of the countdown timer like Best Time - "00:04".
But asides that everything works perfectly, thank you so much for your efforts and contributions for me and making my CopperCube journey smooth so far. I'm so grateful, I'll be posting the link of the final game on the forum today, you can check it out to see how your effort affected the game. Again, thanks.

person icon
okeoke
Registered User
Quote
2023-09-17 20:43:01

No problem, I'm glad you found it useful:)


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 |