Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
I created a system in my game where there player has a Score and a High Score and the high score is saved every few seconds(100ms) and loaded before first drawing. I'm trying to create a system where there is a Daily Target and the value changes based on the high score. For instance, if the player's high score is 500pts, the daily target can be 1000pts. Now I've setup a system already where I added a "If a variable has value do something" behavior where if high score is less than for instance, 200, I set or change a variable called "daily" equals 500 which is daily target. Now I did this a couple of more times where when the player's high score is is less than various values and I set or change variable to be equals a value. Now I have a 2D overlay text which displays the daily target but the problem I have now is that if for instance a players high score is 500 and I have different behaviors of "If a variable has value do something" where high score is less than different values let's say high score less than 1000, 2000, etc. Now the value 500 is less than both 1000 and 2000 so the 2d overlay would display the daily target as 2000 not 1000. I'll like to know how I can solve this. |
||||
|
Now I also tried adding the behavior of "If variable has value do something" where variable hiscore = 200 (not less than 200 this time), the I set my daily target to 500 with variable daily. But this didn't work too because players can have a different values e.g 250, 355,245, 580,490,etc and I cannot add a behavior of "If variable has value do something" for every single possible score value a player can have so I had to resort to the "less than a value" method. |
||||
|
I really hope someone can help me on this. ![]() |
||||
|
Hi dynamogames, Could be done with js action. Could you clarify the following: - what happens if a player gets the daily goal? - how do you actually calculate the daily goal - isd there a mathematical function or sort of a table? |
||||
|
|
||||
|
I would use a multiplier for the price |
||||
|
Ok why not:) you can find a demo here: https://drive.google.com/file/d/1cLKefQX0fUUCaCPr3a47jMbSjJhRNj5E/view?usp=sharing There is a script called "daily target" that should be added to scene's "before first draw". It has some configurable parameters to it you need to set: hiscoreVarName - type in a name of your hign score variable dailyGoalVarName - type in a name of your daily goal variable dailyTextPrefix - prefix of the text which your node shows dailyReachedText - the postfix which shows as the goal is reaced oneDailyGoalPerDay - set 0 if you want the daily goal to be updated multiple times during the day, set 1 if you want it to be fixed for the day and be updated only on the next day if user beats the daily goal dailyGoalTextOverlayNode - select a 2d overlay text node to show information regarding your daily goal |
||||
|
@okeoke if player gets daily goal, a new higher value would be displayed for the player to pass. I calculate the daily goal using the hiScore variable. That is, if player's hiScore is 500, the daily goal would be a value higher than the player's high score. |
||||
|
OK thanks @okeoke I'll check it out |
||||
|
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]), |
||||
|
Wow thanks so much @ okeoke I'm so grateful for all your contributions and your efforts. I'm testing it in CopperCube right now as I speak. I'll be sure to let you know how it goes. |
||||
|
@okeoke I've been able to set it up and it works perfectly. Thanks so so much. |
||||
|
I really wish there is a pin feature on this forum so people who may want to implement similar features in their game can get it very easy. |
|