≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
Variables in CopperCube
Posted by:
(you are not logged in)
Enter the missing letter in: "Inte?national"
(you are not logged in)
Text:
[quote][b][/b] wrote: The full code: [code]// The following embedded xml is for the editor and describes how the action can be edited: // Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action /* <action jsname="action_DailyTarget" description="Daily target"> <property name="hiscoreVarName" type="string" default="" /> <property name="dailyGoalVarName" type="string" default="" /> <property name="dailyTextPrefix" type="string" default="Daily goal:" /> <property name="dailyReachedText" type="string" default="(reached)" /> <property name="oneDailyGoalPerDay" type="boolean" default="1" /> <property name="dailyGoalTextOverlayNode" type="scenenode" default="" /> </action> */ action_DailyTarget = function () { } action_DailyTarget.prototype.execute = function (node) { this.dailyGoalVarFilePath = 'dailygoal.txt'; // read high score value from the provided var name // cast to int var hiScore = parseInt(ccbGetCopperCubeVariable(this.hiscoreVarName)); // calculate the expected daily goal // find closes hundredth value and increase by 2 var dailyGoalValue = (Math.round(hiScore / 100) * 100) * 2; // if no hi score found - daily goal should be 100 if (dailyGoalValue === 0) dailyGoalValue = 100; // set daily goal variable ccbSetCopperCubeVariable(this.dailyGoalVarName, dailyGoalValue); // check if daily goal file does not exist // or if daily goal can change multiple times during the day // write file in this case if (!ccbFileExist(this.dailyGoalVarFilePath) || !this.oneDailyGoalPerDay) { this.writeDailyGoalFile(dailyGoalValue); // show text node screen ccbSetSceneNodeProperty(this.dailyGoalTextOverlayNode, 'Text', this.dailyTextPrefix + ' ' + dailyGoalValue); // since there was no file and we wrote the first value there is nothing // todo anymore return; } // if file exist, we need to read the data // in case the file is corrupt just rewrite a new file var curDailyGoalData; try { curDailyGoalData = this.readDailyGoalFile(); } catch (e) { this.writeDailyGoalFile(dailyGoalValue); // nothing else to do stop the execution return; } // proceed with file date print('proceed with file'); // if date from the file is today and hiscore is greater than daily goal from the file // write daily goal and say that it is already reached // on other case write a newly calcualted daily goal and show it on the text node if (this.checkIsToday(curDailyGoalData.date) && hiScore > curDailyGoalData.score) { ccbSetSceneNodeProperty(this.dailyGoalTextOverlayNode, 'Text', this.dailyTextPrefix + ' ' + curDailyGoalData.score + ' ' + this.dailyReachedText); } else { this.writeDailyGoalFile(dailyGoalValue); ccbSetSceneNodeProperty(this.dailyGoalTextOverlayNode, 'Text', this.dailyTextPrefix + ' ' + dailyGoalValue); } } // function which writes daily goal file // file format is date|value // we use local date to get current day action_DailyTarget.prototype.writeDailyGoalFile = function (dailyGoal) { ccbWriteFileContent(this.dailyGoalVarFilePath, (new Date()).toDateString() + '|' + dailyGoal); } action_DailyTarget.prototype.readDailyGoalFile = function () { // split filecontent by | since that is something we used to separate date from score value var dataArr = ccbReadFileContent(this.dailyGoalVarFilePath).split('|'); // first value will be date - create a Date from the string representation // second value will be score - it's written in a string format, parse it to int return { date: new Date(dataArr[0]), [/quote]
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