how to convert seconds to minutes:seconds in as3 - actionscript-3

hi to all i am new in action script 3 in flash cs6 im creating a game with a timer
i want to make the seconds to minutes:seconds format
example:
120 seconds to 2:00
this is my code:
var countDownDec:Number = 1;
var totalSecs = 120;
var countDownSecs = totalSecs;
counter.text = countDownSecs;
var time:Timer = new Timer(countDownDec*1000);
time.addEventListener(TimerEvent.TIMER, tick);
time.reset();
countDownSecs = totalSecs;
counter.text = countDownSecs;
time.start();
var frameLbl:FrameLabel;
function tick(e:TimerEvent):void {
time.start();
if(countDownSecs == 0){
time.stop();
countDownSecs = totalSecs;
gotoAndPlay('timesUp');
TimesUp.play();
}
else{
countDownSecs = countDownSecs - countDownDec;
counter.text = countDownSecs;
}
}
please help me to my problem

Code 100% working :
var count_down_interval:Number = 1
var total_seconds:Number = 120
var count_down_seconds:Number = total_seconds
var timer:Timer = new Timer(count_down_interval * 1000)
timer.addEventListener(TimerEvent.TIMER, timer_on_Tick)
function timer_on_Tick(e:TimerEvent):void {
if(count_down_seconds == 0){
timer.stop()
count_down_seconds = total_seconds
trace('game over')
} else{
count_down_seconds -= count_down_interval
counter.text = convert_time(count_down_seconds)
}
}
timer.start();
counter.text = convert_time(count_down_seconds)
function convert_time(time) {
var h, m, s:Number, t:String, a:Array
if(isNaN(time)){ // 05:37 -> 337 seconds
t = time
a = t.split(':')
if(a.length > 2){
h = int(a[0]), m = int(a[1]), s = int(a[2])
} else {
h = 0, m = int(a[0]), s = int(a[1])
}
return h*3600 + m*60 + s
} else { // 337 -> 05:37
t = ''
h = int(time/3600)
m = int((time-(h*3600))/60)
if(time >= 3600) t += (h<10 ? '0' : '') + h + ':'
t += (m<10 ? '0' : '') + m + ':'
t += (time % 60<10 ? '0' : '') + int(time % 60)
return t
}
}

Divide by 60 and round down for minutes, modulo (%) 60 for seconds
var totalSecs = 120;
var minutes = Math.floor(totalSecs / 60);
var seconds = totalSecs % 60;
var timeInMinutesSeconds = minutes + ":" + seconds;
EDIT:
Try this:
var countDownDec:Number = 1;
var totalSecs:int = 120;
var countDownSecs:int = totalSecs;
counter.text = getCountDownSecsText(countDownSecs);
var time:Timer = new Timer(countDownDec*1000);
time.addEventListener(TimerEvent.TIMER, tick);
var frameLbl:FrameLabel;
function tick(e:TimerEvent):void {
if(countDownSecs == 0) {
time.stop();
countDownSecs = totalSecs;
gotoAndPlay('timesUp');
TimesUp.play();
} else {
countDownSecs = countDownSecs - countDownDec;
counter.text = getCountDownSecsText(countDownSecs);
}
}
private function getCountDownSecsText(currentAmountSecs:int):String{
var minutes:int = Math.floor(currentAmountSecs / 60);
var seconds:int = currentAmountSecs % 60;
var prependString:String = "";
if( minutes > 9 ) {
prependString = "0";
}
return prependString + minutes + ":" + seconds;
}

Related

Auto reply Gmail excluding some address and object

I would like to no autoreply to some email objects (es: no_reply) and some email address.
I've tried with this code but it doesn't work. What is wrong with it?
function autoReply() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var exclude = ['noreply','no_reply','assistenza'];
var exclude_obj = ['Email ricevuta','Messaggio ricevuto','test'];
var wkend = [6,0]; // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
var wkendMessage = "Ciao";
var wkdayMessage = "Ciao ciao";
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
if (wkend.indexOf(day) > -1 || (day == 5 && hour < 18)) {
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('subject:"xxx" is:inbox after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
if(!exclude.includes(threads[i].getMessages()[0].getFrom().split("#")[0])
&& !exclude_obj.includes(threads[i].getMessages()[0].getFrom()[0])
){
threads[i].reply(wkendMessage);
}
}
}
else if ((hour > 11 && hour < 19) || (hour < 0 && hour > 11) ) {
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
if(!exclude.includes(threads[i].getMessages()[0].getFrom().split("#")[0])
&& !exclude_obj.includes(threads[i].getMessages()[0].getFrom()[0])
){
threads[i].reply(wkdayMessage);
}
}
}
}
function doGet() {
return ContentService.createTextOutput("");
}

how to add multiple canvas on same html page

I copied a puzzle code. Now i need to add more puzzles in the same page how i can do that with this javascript. Please anyone guide me to how to handle this code for making multiple puzzles, I have basic skill in javascript, I am trying to add another variable for new puzzle it's not working...
const PUZZLE_DIFFICULTY = 2;
const PUZZLE_HOVER_TINT = '#009900';
var _stage;
var _canvas;
var _img;
var _pieces;
var _puzzleWidth;
var _puzzleHeight;
var _pieceWidth;
var _pieceHeight;
var _currentPiece;
var _currentDropPiece;
var _mouse;
function init() {
_img = new Image();
_img.addEventListener('load', onImage, false);
_img.src = "http://lorempixel.com/output/animals-q-g-640-480-3.jpg";
}
function onImage(e) {
_pieceWidth = Math.floor(_img.width / PUZZLE_DIFFICULTY)
_pieceHeight = Math.floor(_img.height / PUZZLE_DIFFICULTY)
_puzzleWidth = _pieceWidth * PUZZLE_DIFFICULTY;
_puzzleHeight = _pieceHeight * PUZZLE_DIFFICULTY;
setCanvas();
initPuzzle();
}
function setCanvas() {
_canvas = document.getElementById('puzzle');
_stage = _canvas.getContext('2d');
_canvas.width = _puzzleWidth;
_canvas.height = _puzzleHeight;
_canvas.style.border = "1px solid black";
}
function initPuzzle() {
_pieces = [];
_mouse = {
x: 0,
y: 0
};
_currentPiece = null;
_currentDropPiece = null;
_stage.drawImage(_img, 0, 0, _puzzleWidth, _puzzleHeight, 0, 0, _puzzleWidth, _puzzleHeight);
createTitle("Click to Start Puzzle");
buildPieces();
}
function createTitle(msg) {
_stage.fillStyle = "#000000";
_stage.globalAlpha = .4;
_stage.fillRect(100, _puzzleHeight - 40, _puzzleWidth - 200, 40);
_stage.fillStyle = "#FFFFFF";
_stage.globalAlpha = 1;
_stage.textAlign = "center";
_stage.textBaseline = "middle";
_stage.font = "20px Arial";
_stage.fillText(msg, _puzzleWidth / 2, _puzzleHeight - 20);
}
function buildPieces() {
var i;
var piece;
var xPos = 0;
var yPos = 0;
for (i = 0; i < PUZZLE_DIFFICULTY * PUZZLE_DIFFICULTY; i++) {
piece = {};
piece.sx = xPos;
piece.sy = yPos;
_pieces.push(piece);
xPos += _pieceWidth;
if (xPos >= _puzzleWidth) {
xPos = 0;
yPos += _pieceHeight;
}
}
document.onmousedown = shufflePuzzle;
}
function shufflePuzzle() {
_pieces = shuffleArray(_pieces);
_stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);
var i;
var piece;
var xPos = 0;
var yPos = 0;
for (i = 0; i < _pieces.length; i++) {
piece = _pieces[i];
piece.xPos = xPos;
piece.yPos = yPos;
_stage.drawImage(_img, piece.sx, piece.sy, _pieceWidth, _pieceHeight, xPos, yPos, _pieceWidth, _pieceHeight);
_stage.strokeRect(xPos, yPos, _pieceWidth, _pieceHeight);
xPos += _pieceWidth;
if (xPos >= _puzzleWidth) {
xPos = 0;
yPos += _pieceHeight;
}
}
document.onmousedown = onPuzzleClick;
}
function onPuzzleClick(e) {
if (e.layerX || e.layerX == 0) {
_mouse.x = e.layerX - _canvas.offsetLeft;
_mouse.y = e.layerY - _canvas.offsetTop;
} else if (e.offsetX || e.offsetX == 0) {
_mouse.x = e.offsetX - _canvas.offsetLeft;
_mouse.y = e.offsetY - _canvas.offsetTop;
}
_currentPiece = checkPieceClicked();
if (_currentPiece != null) {
_stage.clearRect(_currentPiece.xPos, _currentPiece.yPos, _pieceWidth, _pieceHeight);
_stage.save();
_stage.globalAlpha = .9;
_stage.drawImage(_img, _currentPiece.sx, _currentPiece.sy, _pieceWidth, _pieceHeight, _mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
_stage.restore();
document.onmousemove = updatePuzzle;
document.onmouseup = pieceDropped;
}
}
function checkPieceClicked() {
var i;
var piece;
for (i = 0; i < _pieces.length; i++) {
piece = _pieces[i];
if (_mouse.x < piece.xPos || _mouse.x > (piece.xPos + _pieceWidth) || _mouse.y < piece.yPos || _mouse.y > (piece.yPos + _pieceHeight)) {
//PIECE NOT HIT
} else {
return piece;
}
}
return null;
}
function updatePuzzle(e) {
_currentDropPiece = null;
if (e.layerX || e.layerX == 0) {
_mouse.x = e.layerX - _canvas.offsetLeft;
_mouse.y = e.layerY - _canvas.offsetTop;
} else if (e.offsetX || e.offsetX == 0) {
_mouse.x = e.offsetX - _canvas.offsetLeft;
_mouse.y = e.offsetY - _canvas.offsetTop;
}
_stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);
var i;
var piece;
for (i = 0; i < _pieces.length; i++) {
piece = _pieces[i];
if (piece == _currentPiece) {
continue;
}
_stage.drawImage(_img, piece.sx, piece.sy, _pieceWidth, _pieceHeight, piece.xPos, piece.yPos, _pieceWidth, _pieceHeight);
_stage.strokeRect(piece.xPos, piece.yPos, _pieceWidth, _pieceHeight);
if (_currentDropPiece == null) {
if (_mouse.x < piece.xPos || _mouse.x > (piece.xPos + _pieceWidth) || _mouse.y < piece.yPos || _mouse.y > (piece.yPos + _pieceHeight)) {
//NOT OVER
} else {
_currentDropPiece = piece;
_stage.save();
_stage.globalAlpha = .4;
_stage.fillStyle = PUZZLE_HOVER_TINT;
_stage.fillRect(_currentDropPiece.xPos, _currentDropPiece.yPos, _pieceWidth, _pieceHeight);
_stage.restore();
}
}
}
_stage.save();
_stage.globalAlpha = .6;
_stage.drawImage(_img, _currentPiece.sx, _currentPiece.sy, _pieceWidth, _pieceHeight, _mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
_stage.restore();
_stage.strokeRect(_mouse.x - (_pieceWidth / 2), _mouse.y - (_pieceHeight / 2), _pieceWidth, _pieceHeight);
}
function pieceDropped(e) {
document.onmousemove = null;
document.onmouseup = null;
if (_currentDropPiece != null) {
var tmp = {
xPos: _currentPiece.xPos,
yPos: _currentPiece.yPos
};
_currentPiece.xPos = _currentDropPiece.xPos;
_currentPiece.yPos = _currentDropPiece.yPos;
_currentDropPiece.xPos = tmp.xPos;
_currentDropPiece.yPos = tmp.yPos;
}
resetPuzzleAndCheckWin();
}
function resetPuzzleAndCheckWin() {
_stage.clearRect(0, 0, _puzzleWidth, _puzzleHeight);
var gameWin = true;
var i;
var piece;
for (i = 0; i < _pieces.length; i++) {
piece = _pieces[i];
_stage.drawImage(_img, piece.sx, piece.sy, _pieceWidth, _pieceHeight, piece.xPos, piece.yPos, _pieceWidth, _pieceHeight);
_stage.strokeRect(piece.xPos, piece.yPos, _pieceWidth, _pieceHeight);
if (piece.xPos != piece.sx || piece.yPos != piece.sy) {
gameWin = false;
}
}
if (gameWin) {
setTimeout(gameOver, 500);
}
}
function gameOver() {
document.onmousedown = null;
document.onmousemove = null;
document.onmouseup = null;
initPuzzle();
alert("you Won")
}
function shuffleArray(o) {
for (var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}
<body onload="init();">
<canvas id="puzzle"></canvas>
</body>

GAS - Script execution time too long / Workaround?

I have a script that takes more than 5 minutes to execute. So it will be aborted after 5 minutes with the information that the execution time is too long.
Now I am looking for a solution to handle this. In the following example I would like to interrupt when var = i has reached a value of 300 and then continue with i = 301. Is this an option for a workaround? If so, how has the code to be adapted?
var xy = 1100;
for (var = i; i<= xy; i++){
{
do_some_stuff();
}
}
In practice my code is the following....and the loop is starting with for(var i = 3; i <= lastrow +1; i++) lastrow has a value of 1500.
function Create_geodata()
{
var Geodata = getSheetById(1702838837);
var Geojson_Data = getSheetById(1515926044);
var Control_Panel = getSheetById(1102907697);
Geodata.getRange('I4').setValue('Yes');
var Hyperlink_Geodata = Control_Panel.getRange('O18').getValue();
var document_missing_ID = Control_Panel.getRange('O24').getValue();
var Umap_Hyperlink = Control_Panel.getRange('L20').getValue();
var umap_zoom = Control_Panel.getRange('N22').getValue();
var Own_ID_Sort_Setting = Control_Panel.getRange('O30').getValue();
var Own_ID_Sort = Control_Panel.getRange('M32').getValue();
var Threshold_Altitude = Control_Panel.getRange('N28').getValue();
var Automatic_Altitude_Removal = Control_Panel.getRange('O26').getValue();
var Cat_A = Control_Panel.getRange('C36').getValue();
var Cat_B = Control_Panel.getRange('C38').getValue();
var Cat_C = Control_Panel.getRange('C40').getValue();
RESET_Geodata(); //Clear data before proceed
if (Own_ID_Sort_Setting)
{standard_sort_column = Own_ID_Sort}
else
{standard_sort_column = "name"}
var data = Geojson_Data.getDataRange().getValues();
var col1 = data[0].indexOf(standard_sort_column) + 1;
var col2 = data[0].indexOf('coordinates') + 1;
var col3 = data[0].indexOf('name') + 1;
var col4 = data[0].indexOf('description') + 1;
var col1_Char = columnToLetter(col1); //last row of column where sort-criteria is located
var col2_Char = columnToLetter(col2);
var col3_Char = columnToLetter(col3);
var col4_Char = columnToLetter(col4);
var lastrow_col1 = Geojson_Data.getRange(col1_Char + ':' + col1_Char).getValues();
lastrow_col1 = lastrow_col1.filter(String).length;
var lastrow = Geojson_Data.getLastRow();//last row of complete sheet
var lc = Geojson_Data.getLastColumn(); //last column
var lc_Char = columnToLetter(lc);
var dc = 0;
Geojson_Data.getRange('N1').setValue(col1);
if (!document_missing_ID)
{
for(var t = 2; t <= lastrow; t++)
{
if (Geojson_Data.getRange(t,col1).getValue() == "")
{
Geojson_Data.deleteRow(t);
}
}
}
else
{
for(var t = 2; t <= lastrow; t++)
{
if (Geojson_Data.getRange(t,col1).getValue() == "")
{
dc++;
var formattedNumber = ("000" + dc).slice(-4);
Geojson_Data.getRange(t,col1).setValue('ZZ_' + formattedNumber);
}
}
}
Geojson_Data.getRange('A2:' + lc_Char + lastrow).sort(col1);
Geojson_Data.getRange(col1_Char + 2 + ':' + col1_Char + lastrow).copyTo(Geodata.getRange('A3:A' + lastrow),{contentsOnly: true});
Geojson_Data.getRange(col2_Char + 2 + ':' + col2_Char + lastrow).copyTo(Geodata.getRange('F3:F' + lastrow),{contentsOnly: true});
Geojson_Data.getRange(col3_Char + 2 + ':' + col3_Char + lastrow).copyTo(Geodata.getRange('B3:B' + lastrow),{contentsOnly: true});
Geojson_Data.getRange(col4_Char + 2 + ':' + col4_Char + lastrow).copyTo(Geodata.getRange('D3:D' + lastrow),{contentsOnly: true});
var geodata_sorted = '';
var route_length = 0;
for(var i = 3; i <= lastrow +1; i++)
{
var pr = 0;
var fl = false;
var distance_neighbour_points = 0;
var Ar = Geodata.getRange('F' + i).getValue();
Ar = Ar.split(',');
var Ar_Anz = Ar.length - 1;
for(var b = 0; b <= Ar_Anz; b=b+2)
{
if ((Ar_Anz - b) != 0)
{
var E_Lat = Ar[b];
var E_Lon = Ar[b + 1];
if (fl)
{
var A_Lat = Ar[b - 2];
var A_Lon = Ar[b - 1];
distance_neighbour_points = distVincenty(A_Lat, A_Lon, E_Lat, E_Lon);
if (Automatic_Altitude_Removal && (distance_neighbour_points > Threshold_Altitude))
{
b++;
E_Lat = Ar[b];
E_Lon = Ar[b + 1];
A_Lat = Ar[b - 3];
A_Lon = Ar[b - 2];
}
route_length = route_length + distVincenty(A_Lat, A_Lon, E_Lat, E_Lon);
}
pr++;
fl = true;
}
geodata_sorted = geodata_sorted + E_Lat + ',' + E_Lon;
if ((Ar_Anz - b) < 2)
{
}
else
{
geodata_sorted = geodata_sorted + ',';
}
if ((Ar_Anz - b) < 2)
{
pr = parseInt(pr / 2) * 2 + 1;
var Ay = geodata_sorted.split(',');
var Geo_Mitte_Lon = Ay[pr - 1];
var Geo_Mitte_Lat = Ay[pr];
var googlemaps = 'https://maps.google.com/?q=' + Geo_Mitte_Lat + ',' + Geo_Mitte_Lon;
var umap = 'https://umap.openstreetmap.fr/de' + '/map/' + Umap_Hyperlink + '#' + umap_zoom + '/' + Geo_Mitte_Lat + '/' + Geo_Mitte_Lon;
Geodata.getRange(i, 3).setValue(route_length / 1000);
Geodata.getRange(i, 6).setValue(geodata_sorted);
Geodata.getRange(i, 7).setValue(googlemaps);
Geodata.getRange(i, 8).setValue(umap);
//Verlinkung
if (Hyperlink_Geodata)
{
var displayName1 = Geodata.getRange(i,1).getValue();
var displayName2 = Geodata.getRange(i,2).getValue();
Geodata.getRange(i,1).setFormula('=HYPERLINK(\"' + googlemaps + '\";\"' + displayName1 + '\")');
Geodata.getRange(i,2).setFormula('=HYPERLINK(\"' + umap + '\";\"' + displayName2 + '\")');
}
geodata_sorted = '';
route_length = 0;
}
}
//Set categories Cat_A,B,C...
var description_content = Geodata.getRange(i,4).getValue();
var regExpA = new RegExp('/*' + Cat_A, 'gi');
var regExpB = new RegExp('/*' + Cat_B, 'gi');
var regExpC = new RegExp('/*' + Cat_C, 'gi');
var compareA = regExpA(description_content);
var compareB = regExpB(description_content);
var compareC = regExpC(description_content);
if (compareC == Cat_C) Geodata.getRange(i,5).setValue(Cat_C);
if (compareB == Cat_B) Geodata.getRange(i,5).setValue(Cat_B);
if (compareA == Cat_A) Geodata.getRange(i,5).setValue(Cat_A);
}
SpreadsheetApp.getActiveSpreadsheet().setActiveSheet(Geodata);
Geodata.getRange('I4').setValue('No');
}

"Lock wait timeout exceeded" when sending data from Google Sheets to MySQL

I wrote an Apps Script macro to send data from a Google spreadsheet to a MySQL table. In a first time, in delete some rows in the table and then I add rows in this table. I sometimes get a "Lock wait timeout exceeded; try restarting transaction" error. Sometimes it runs after 100 seconds, sometimes 4 minutes.
I don't understand what is wrong with this code.
//classeur.insertSheet("feuillebis")
//feuillebis=classeur.getSheets()[1]
//var feuillebis=classeur.getSheetByName('feuillebis')
var classeur = SpreadsheetApp.getActiveSpreadsheet() ;
var feuille = classeur.getActiveSheet();
var host = "107.167.186.180";
var databaseName = "eatology";
var userName = "root";
var password = "eatology";
var port = 3306;
var tableName = "weekly_order";
var url = 'jdbc:mysql://' + host + ':' + port + '/' + databaseName;
var nbrow = feuille.getMaxRows()
function Send_Weekly_Order_To_Data_Base() {
///here are all the connection parameters
var classeur = SpreadsheetApp.getActiveSpreadsheet();
var feuille = classeur.getActiveSheet();
var nbrow = feuille.getMaxRows();
var host = "107.167.186.180";
var databaseName = "eatology";
var userName = "root";
var password = "eatology";
var port = 3306;
var tableName = "weekly_order";
var url = 'jdbc:mysql://' + host + ':' + port + '/' + databaseName;
var conn = Jdbc.getConnection(url, userName, password);
conn.setAutoCommit(false);
///get the weekly_order as an array from the sql
var rowcount = 0;
var stmt2 = conn.createStatement();
var results = stmt2.executeQuery("SELECT * FROM eatology.weekly_order");
while (results.next()) {
if (results.getInt(1) > rowcount){
rowcount = results.getInt(1)
}
}
conn.commit();
results.close();
stmt2.close();
///delete the rows from the current week where we are running the macro
var timezone1 = classeur.getSpreadsheetTimeZone();
var date1 = Utilities.formatDate(feuille.getRange(2, 2).getValue(), timezone1, "yyyy-MM-dd");
var date2 = Utilities.formatDate(feuille.getRange(2, 3).getValue(), timezone1, "yyyy-MM-dd");
var date3 = Utilities.formatDate(feuille.getRange(2, 4).getValue(), timezone1, "yyyy-MM-dd");
var date4 = Utilities.formatDate(feuille.getRange(2, 5).getValue(), timezone1, "yyyy-MM-dd");
var date5 = Utilities.formatDate(feuille.getRange(2, 6).getValue(), timezone1, "yyyy-MM-dd");
var date6 = Utilities.formatDate(feuille.getRange(2, 7).getValue(), timezone1, "yyyy-MM-dd");
///clear the table weekly-order in the database
var stmt1 = conn.createStatement();
var result = stmt1.executeUpdate("DELETE FROM eatology.weekly_order where `Date` = " + "'" + date1 + "'" +" or `Date` = " + "'" + date2 + "'" +" or `Date` = " + "'" + date3 + "'" +" or `Date` = "+ "'" + date4 + "'" +" or `Date` = " + "'" + date5 + "'" +" or `Date` = "+ "'" + date6 + "'" );
//var result = stmt1.executeUpdate("DELETE FROM eatology.weekly_order where `Date` = " + "'" + date1 +"'");
conn.commit();
stmt1.close();
conn.close();
rowcount = rowcount + 1;
var conn = Jdbc.getConnection(url, userName, password);
conn.setAutoCommit(false);
var stmt = conn.prepareStatement('INSERT INTO eatology.weekly_order '
+ '(`Uid`, `Date`, `MP`, `Cname`, `Pname`, `Breakfast`, `Snack1`, `Lunch`, `Snack2`, `Dinner`) values (?,?,?,?,?,?,?,?,?,?)');
var program_name_line = 0;
var array = feuille.getRange(1, 1, nbrow, 7).getValues();
for (var j = 1; j < 7; j = j + 1) {
var inside = 0;
var i = 1;
while (array[i][0] != "Total" && i < 1000) {
i = i + 1
var color = feuille.getRange(i + 1, j + 1).getBackgrounds()
var fi1 = array[i][0].toString();
var fij = array[i][j].toString();
var empty = (fij == "");
var already = 0;
var test11111 = (color != "#5d31ce");
var cas1 = ((empty == false) && (fi1 != "Total") && (inside == 0));
var cas2 = (color == "#5d31ce" && inside == 1);
var cas3 = (empty == false);
if ((fi1 != "Total") && (inside == 0) && color != "#5d31ce") {
program_name_line = i;
inside = 1;
if (empty == false) {
var Uid = rowcount;
var Date1 = (Utilities.formatDate(array[1][j], timezone1, "yyyy-MM-dd"));
var MP = (array[program_name_line][0]);
var place = ((fij).indexOf("-"));
var length = (fij.length);
var Pname = ((fij).substring(place + 1, length));
var Cname = ((fij).substring(0, place));
var list = (meal(MP, Pname));
var Breakfast = list[0];
var Snack1 = list[1];
var Lunch = list[2];
var Snack2 = list[3];
var Dinner = list[4];
if (MP == "TM") {
var Breakfast = 1;
var Snack1 = 1;
var Lunch = 1;
var Snack2 = 1;
var Dinner = 1;
}
rowcount = rowcount + 1;
stmt.setInt(1, Uid);
stmt.setString(2, Date1);
stmt.setString(3, MP);
stmt.setString(4, Cname);
stmt.setString(5, Pname);
stmt.setInt(6, Breakfast);
stmt.setInt(7, Snack1);
stmt.setInt(8, Lunch);
stmt.setInt(9, Snack2);
stmt.setInt(10, Dinner);
stmt.addBatch();
}
}
else if (color == "#5d31ce" && inside == 1) {
inside = 0;
}
else if (empty == false && color != "#5d31ce") {
var Uid = rowcount ;
var Date1 = (Utilities.formatDate(array[1][j], timezone1, "yyyy-MM-dd"));
var MP = (array[program_name_line][0].toString());
var place = ((fij).indexOf("-"));
var length = (fij.length);
var Pname = ((fij).substring(place + 1, length));
var Cname = ((fij).substring(0, place));
var list = (meal(MP, Pname));
var Breakfast = (list[0]);
var Snack1 = (list[1]);
var Lunch = (list[2]);
var Snack2 = (list[3]);
var Dinner = (list[4]);
if (MP == "TM") {
var Breakfast = 1;
var Snack1 = 1;
var Lunch = 1;
var Snack2 = 1;
var Dinner = 1;
}
rowcount = rowcount+1;
stmt.setInt(1, Uid);
stmt.setString(2, Date1);
stmt.setString(3, MP);
stmt.setString(4, Cname);
stmt.setString(5, Pname);
stmt.setInt(6, Breakfast);
stmt.setInt(7, Snack1);
stmt.setInt(8, Lunch);
stmt.setInt(9, Snack2);
stmt.setInt(10, Dinner);
stmt.addBatch();
}
}
}
stmt.executeBatch();
conn.commit();
stmt.close();
conn.close();
}
function meal(MP, Pname){
var result= [0, 0, 0, 0, 0]
//in order to know if we have two snacks or only one because if the programm has more than 1200 cal, there are two snacks, otherwise, only one snack
var two_snacks = 1
if (MP.indexOf("1200") > -1) {
two_snacks = 0
}
//if the program type is '3'
if (Pname.indexOf("3") > -1) {
result[0] = 1;
result[1] = 1;
result[2] = 1;
result[4] = 1;
if (two_snacks == 1) {
result[3] = 1;
}
}
//if the program type is '2'
if (Pname.indexOf("2") > -1 && Pname.indexOf("S") == -1) {
result[0] = 1;
result[1] = 1;
result[2] = 1;
if (two_snacks == 1) {
result[3] = 1;
}
}
//if there is the B letter
if (Pname.indexOf("B") > -1) {
result[0] = 1;
}
//if there is the L letter
if (Pname.indexOf("L") > -1) {
result[2] = 1;
}
//if there is the D letter
if (Pname.indexOf("D") > -1) {
result[4] = 1;
}
//if there is the 2S letter
if (Pname.indexOf("2S") > -1) {
result[1] = 1;
result[3] = 1;
}
//if there is the 1S letter
if (Pname.indexOf("1S") > -1) {
result[1] = 1;
result[1] = 1;
}
return result
}

Blank Maze Generation

Maze is generating in a weird fashion. I do not know why, but it generates and breaks down every wall.
here is the code:
public class Main extends Sprite
{
//ARRAYS
private var maze:Array = new Array();
private var pos:Array = new Array();
//INTEGERS
private var num:int = 50;
private var cellX:int = 0;
private var cellY:int = 0;
private var mazeX:int = num;
private var mazeY:int = num;
//POINTS
private var startCell:Point = new Point();
//SPRITES
private var mazeSpriteT:Sprite = new Sprite();
private var mazeSpriteB:Sprite = new Sprite();
private var mazeSpriteL:Sprite = new Sprite();
private var mazeSpriteR:Sprite = new Sprite();
//broken wall
private var brWall:Sprite = new Sprite();
public function Main():void
{
//creating the initial grid, cells and points
setMaze();
//calling function to generate maze
generate(startCell);
}
public function setMaze():void
{
//clearing the screen from all graphical images
mazeSpriteT.graphics.clear();
mazeSpriteB.graphics.clear();
mazeSpriteR.graphics.clear();
mazeSpriteL.graphics.clear();
brWall.graphics.clear();
maze = new Array();
pos = new Array();
for (var i:int = 0; i < 10; i++) {
maze[i] = new Array();
pos[i] = new Array();
for (var j:int = 0; j < 10; j++) {
//maze
maze[i][j] = new Cell;
maze[i][j].visited = false;
//pos
pos[i][j] = new Point(cellX, cellY);
//graphics
mazeSpriteT.graphics.lineStyle(5, 0x000000, 1);
mazeSpriteB.graphics.lineStyle(5, 0x000000, 1);
mazeSpriteR.graphics.lineStyle(5, 0x000000, 1);
mazeSpriteL.graphics.lineStyle(5, 0x000000, 1);
//toplines
addChild(mazeSpriteT);
mazeSpriteT.graphics.moveTo(mazeX, mazeY);
mazeSpriteT.graphics.lineTo(mazeX + num, mazeY);
mazeSpriteT = new Sprite();
//bottomlines
addChild(mazeSpriteB);
mazeSpriteB.graphics.moveTo(mazeX, mazeY + num);
mazeSpriteB.graphics.lineTo(mazeX + num, mazeY + num);
mazeSpriteB = new Sprite();
//rightlines
addChild(mazeSpriteR);
mazeSpriteR.graphics.moveTo(mazeX + num, mazeY);
mazeSpriteR.graphics.lineTo(mazeX + num, mazeY + num);
mazeSpriteR = new Sprite();
//leftlines
addChild(mazeSpriteL);
mazeSpriteL.graphics.moveTo(mazeX, mazeY);
mazeSpriteL.graphics.lineTo(mazeX, mazeY + num);
mazeSpriteB = new Sprite();
cellX += 10;
mazeX += num;
}
cellX = 0;
cellY += 10;
mazeX = num;
mazeY += num;
}
//maze entrance
startCell = pos[0][0];
}
public function generate(cell:Point):void
{
var cx:int = cell.x / 10;
var cy:int = cell.y / 10;
maze[cy][cx].visited = true;
var neighbours:Array = new Array();
fillNeighbours(neighbours, cell);
trace(neighbours.length);
while (neighbours.length > 0) {
var index:int = (Math.random() * neighbours.length);
Math.floor(index);
var arr:Array = neighbours.splice(index, 1);
var pnt:Point = new Point(arr[0].x, arr[0].y);
breakWall(cell, pnt);
generate(pnt);
//trace("index: " + index);
//trace("obx: " + arr[0].x + " oby: " + arr[0].y);
//trace("pnt: " + pnt);
}
}
public function fillNeighbours(neighbours:Array, cell:Point):Array
{
var cx:int = cell.x / 10;
var cy:int = cell.y / 10;
/*for (var i:int = 0; i < maze.length; i++) {
for (var j:int = 0; j < maze[i].length; j++) {
//outerwall parameters
maze[0][j].north = false;
maze[maze.length - 1][j].south = false;
maze[i][maze[i].length-1].east = false;
maze[i][0].west = false;
}
} */
//south neigbours
if (cy < maze.length - 1) {
if (maze[cy + 1][cx].visited == true) {
maze[cy][cx].south = false;
} else {
neighbours.push(pos[cy + 1][cx]);
}
}
if (cy > 0) {
//north neighbours
if (maze[cy - 1][cx].visited == true) {
maze[cy][cx].north = false;
} else {
neighbours.push(pos[cy - 1][cx]);
}
}
if (cx < maze.length - 1) {
//east neighbours
if (maze[cy][cx + 1].visited == true) {
maze[cy][cx].east = false;
} else {
neighbours.push(pos[cy][cx + 1]);
}
}
if (cx > 0) {
//west neighbours
if (maze[cy][cx - 1].visited == true) {
maze[cy][cx].west = false;
} else {
neighbours.push(pos[cy][cx - 1]);
}
}
trace("--");
return(neighbours);
}
public function breakWall(cell:Point, pnt:Point):void
{
var cx:int = cell.x / 10;
var cy:int = cell.y / 10;
var px:int = pnt.x / 10;
var py:int = pnt.y / 10;
brWall.graphics.lineStyle(5, 0xFFFFFF, 1); //white walls
addChild(brWall);
trace(cx, px);
if (cy == py) { //horizontal transition
if (cx > px) { //right to left
brWall.graphics.moveTo((cx * num) + num, (cy * num) + num);
brWall.graphics.lineTo((cx * num) + num, (cy * num) + (num * 2));
} else if (cx < px) { //left to right
brWall.graphics.moveTo((cx * num) + (num * 2), (cy * num) + (num * 2));
brWall.graphics.lineTo((cx * num) + (num * 2), (cy * num) + num);
}
}
if (cx == px) { //vertical transition
if (cy > py) { //down to up
brWall.graphics.moveTo((cx * num) + (num * 2), (cy * num) + num);
brWall.graphics.lineTo((cx * num) + num, (cy * num) + num);
} else if (cy < py){ //up to down
brWall.graphics.moveTo((cx * num) + num, (cy * num) + (num * 2));
brWall.graphics.lineTo((cx * num) + (num * 2), (cy * num) + (num * 2));
}
}
brWall = new Sprite();
}
}
}
I have been praying for help. Be the one to answer my prayers (I will give you five internet dollars).
I'm not too sure I understand completely. You're running a loop that breaks down each wall
while (neighbours.length > 0) {
var index:int = (Math.random() * neighbours.length);
Math.floor(index);
var arr:Array = neighbours.splice(index, 1);
var pnt:Point = new Point(arr[0].x, arr[0].y);
breakWall(cell, pnt);
generate(pnt);
//trace("index: " + index);
//trace("obx: " + arr[0].x + " oby: " + arr[0].y);
//trace("pnt: " + pnt);
}
Just remove breakWall(cell,pnt)?