How can we display Time in our Game cocos2dx - cocos2d-x

I tried to use :
DelayTime*
Second Schedule() function
but nothing happened.
I just want to display my time in HUD Layer.
Thanks in Advance...

Update a time variable in a scheduled function with 1 second delay. Make a counter increase on each call of the function and calculate time like following:
HH = Counter /3600;
MM = (Counter %3600)/60;
SS: ((counter%3600)%60);

Related

Running a Function in the background while asking for more inputs

I am creating a little data processing script using selenium. Where I input my values and it runs a function to do the task on a website. I would like to queue inputs so that I can enter the new values while it works on the old ones.
while customername != 1:
print("Customer name")
customername = input()
print("Credit amount")
creditamount = input()
addcredit(driver, customername, creditamount)
How would I get the function addcredit() to run while the loop continues and asks me for the next set of inputs?
Thank you all!
So after a bit more research, I used Threading.
p1 = threading.Thread(target=addcredit, args=(driver, customername, creditamount))
p1.start()
this is allowing my script to run as intended.. where it starts the action and then allows me to type more data in to run the action again. from my understanding when the function called in the second thread sleeps it bounces back to the first thread and continues on. someone, please correct me if I am wrong.

Google Sheets JS Event

I created a countdown timer in google sheets based off a set date and time.
I know how to change the date with javascript events but how would I create a trigger for the event when the time reaches 0?
Thanks in advance.
My code:
'
function dateChange(A1) {
var d = new Date("4/10/2020 00:00:00");
d.setDate(15);
}
'
Solution
Based on my understanding of your question, you are basically trying to trigger something in your sheet after you reach a certain date. Please correct me if I understood wrongly.
To achieve this, you will need to use a time driven trigger for your script function.
Go to your script and create a function with what you want to run when the countdown is 0 (i.e when you reach that specific date). In this example I am setting the C1 cell to the value TIME'S UP.
function test() {
SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('C1').setValue('TIMES IS UP');
}
In your script window, head over to Edit-> Current's project triggers and add the following trigger as shown in the following picture (but of course changing the date limit of your countdown, in your case the 04/10/2020 00:00.
Done ! Now this will trigger once the countdown reaches that date.
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

Adding multiple contacts exceeds time

I'm trying to insert/update multiple contacts (1000+) to google like that:
(in cycle:)
if (contact == null) {
contact = ContactsApp.createContact(first_name, last_name, email);
group.addContact(contact);
} else {
contact.setFullName(first_name+' '+last_name);
contact.setGivenName(first_name);
contact.setFamilyName(last_name);
}
It is working properly however in about 1 minute (100-130 contacts added) the script stops with:
Error Exceeded maximum execution time
Is there a way around this?
Issue:
Apps Script has an execution time limit of 6 or 30 minutes, depending on your account. You are most likely reaching this limit.
Workaround:
To avoid this, you can split the actions you want to perform into different executions by setting a time-based trigger that will fire each successive execution after the previous one has finished. I guess your function has a loop, so you could follow these steps:
Find out how many iterations the script can go through before reaching the time limit (probably 6 minutes). Each execution will have to go through this amount of iterations before stopping.
Create the following time-based trigger at the end of your function: after(durationMilliseconds). Thanks to this, you can run whatever function you specify after the amount of milliseconds you indicate. After each execution, a trigger will be created to fire the next one.
Make your loop a for loop. Because you have to split the loop, you have to store the loop counter (lets call it i) somewhere (you could use PropertiesService at the end of each execution, or write it in the spreadsheet) and retrieve it at the beginning of the next, so that each in successive execution, the script knows where to resume the loop. See, for example, this answer if you don't know how to store and retrieve script properties.
Sample code (check inline comments):
function createContacts() {
// Whatever your code outside the loop is
var i_old = // Retrieve i stored in previous execution (from PropertiesService? Spreadsheet?) (should be 0 if first execution)
var n_int = 100 // Number of iterations that can be done in a single execution without reaching time limit (change accordingly)
var total = 1000 || yourVariable.length // Total number of iterations (change accordingly)
// Loop starts at previous i store until it reaches the specified number of iterations for one execution or reaches the total number:
for(var i = i_old; i <= i_old + n_int && i <= total; i++) {
// Whatever your code inside the loop is
}
// Store i somewhere (PropertiesService? Spreadsheet?)
if (i <= total) { // Create trigger if i hasn't reach the total number of iteration
ScriptApp.newTrigger("createContacts")
.timeBased()
.after(1000 * 60) // This fires the function 1 minute after the current execution ends. Change this time according to your preferences
.create();
}
}
Note:
Please notice that only 1,000 or 2,000 contacts (depending on the account type) can be created daily.
Reference:
Current quotas
Apps Script: Current limitations
PropertiesService
after(durationMilliseconds)

Mode set to have the script make calls only every 2 minutes inside the every 1 minute trigger. (Google App Script)

function All() {
var ss = SpreadsheetApp.getActive();
ss.getRange('Página1!A6').setFormula('=IF(ISEVEN(MINUTE(NOW())),"Ok","Error")')
ss.getRange('Página1!A6').copyTo(ss.getRange('Página1!A6'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
if (ss.getSheetByName('Página1').getRange("A6").getValues()[0][0]=="Ok"){
//History
ss.getRange('Página1!D1').setFormula('=IFERROR(FILTER({C:C;H1},{C:C;H1}<>""))');
ss.getRange('Página1!D1:D').copyTo(ss.getRange('Página1!C1'),
}
}
Google has triggers every 1 minute, 5 minutes, 10 minutes, 15 minutes and 30 minutes.
For this model, I use the 1 minute trigger!
To bypass this and be able to turn it on every 2 minutes instead of 1 minute (because it weighs a lot in the spreadsheet and occasionally creates errors), to deflect this I created this model where it analyzes if the minute of the current time is odd or even. If even, it activates the rest of the script, if odd it ends without doing anything else.
I would like to know if I could do this same thing, but instead of throwing the function into a cell, copy the value so that the formula NOW() doesn't keep updating all the time and so on ... same step but directly in the script, without moving the spreadsheet with unnecessary calls.
And if it would also be possible to do this to set the script to work every 3 minutes instead of 2 minutes as I managed to do.
Instead of using a sheet with a formula to determine if the minute is even or odd, you can use the Apps Script alternative.
I am using the %(Remainder) operator to get the reminder of a division by 2. If it's zero then the number is odd.
The equivalent for MINUTE(NOW()) is achieved with the Javascript Date new Date().getMinutes()
function myFunction() {
if (new Date().getMinutes()%2==0) { //If the minute is odd.
//Your code here
} //No need for else.
}
Instead of modifying your spreadsheet use the Properties Service to store the last time you script ran. Bear in mind that the Properties Service only stores strings, so you will have to convert the Date object to an string an viceversa.
Related
How can I modify a trigger so that it emails upon edit, but not so quickly?

Date And Time Shown Whithout Updating AS3

I am currently trying to show local date and time (of any user that will view my animation)
in a dynamic text field (instance name:DateTime).
i found many tutorials and methods but what i want to do is show current date and time whithout updating seconds/minutes or anything. Just static date and time when the movie entered the frame.
I am using ActionScript3.
I apologise if i am not very clear. can't really express my self in english
Thanks in advance
//...
var d:Date = new Date();
var dateText:String = d.toLocaleString();
DateTime.text = dateText;
//suggestion: dont use capital letters for instance names
//keep them for class names
Date is top level afaik so you don't need to import it.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html
also if you post some code with your question next time it is easier to help