I have a question about my function.
This is my function :
function checkKind()
{
var i:Number = new Number;
for (i=0 ; i<9 ; i++)
{
if (pValue[i] >= 1 && pValue[i] <= 13)
{
pKind[i] = 1;
}
else if (pValue[i] >= 14 && pValue[i] <= 26)
{
pKind[i] = 2;
}
else if (pValue[i] >= 27 && pValue[i] <= 39)
{
pKind[i] = 3;
}
else if (pValue[i] >= 40 && pValue[i] <= 52)
{
pKind[i] = 4;
}
}
}
pKind[i] is always filled up with number 1, so pKind[i] = 1.
I've already checked the pValue[i] which is properly filled.
Can someone help me to see what is wrong in my code ?
Related
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("");
}
I know this issue has been posted about quite a few times but I'm still struggling to make it work. I have the code below:
function conditionalFormat (subGradeRange, colourRange, colourRangeVals) {
subGradeRange.setBorder(true, true, true, true, true, true);
subDash.setColumnWidths(11, 11, 40)
subDash.setColumnWidth(10, 70);
subDash.setColumnWidths(22, 4, 80);
subGradeRange.setHorizontalAlignment("center");
var colours = [];
for (var i = 1; i < colourRangeVals.length; i++) {
colours[i] = [];
for (var j = 0; j < colourRangeVals[i].length; j++) {
var avgTarget = subDash.getRange("O1").getValue();
var gradeCell = subDash.getRange(3, j + 12).getValue();
var avgTargetCell = subSheetPP.getRange(i + 1, 17).getValue();
var mockGradeCell = subDash.getRange(i + 3, j + 12);
var mockGradeCellVal = mockGradeCell.getValue();
if (avgTarget == 0 && gradeCell > avgTargetCell && mockGradeCellVal >= 0) {
colours[i][j] = "#dabeec";
} else if (avgTarget == -1 && gradeCell > avgTargetCell -1 && mockGradeCellVal >= 0) {
colours[i][j] = "#dabeec";
} else if (avgTarget == -2 && gradeCell > avgTargetCell - 2 && mockGradeCellVal >= 0) {
colours[i][j] = "#dabeec";
} else if (avgTarget == 0 && gradeCell == avgTargetCell && mockGradeCellVal >= 0) {
colours [i][j] = "#b8dac1";
} else if (avgTarget == -1 && gradeCell == avgTargetCell -1 && mockGradeCellVal >= 0) {
colours [i][j] = "#b8dac1";
} else if (avgTarget == -2 && gradeCell == avgTargetCell - 2 && mockGradeCellVal >= 0) {
colours [i][j] = "#b8dac1";
} else if (avgTarget == 0 && gradeCell < avgTargetCell && mockGradeCellVal >= 0) {
colours [i][j] = "#e7b3b3";
} else if (avgTarget == -1 && gradeCell < avgTargetCell - 1 && mockGradeCellVal >= 0) {
colours [i][j] = "#e7b3b3";
} else if (avgTarget == -2 && gradeCell < avgTargetCell - 2 && mockGradeCellVal >= 0) {
colours [i][j] = "#e7b3b3";
} else {
colours [i][j] = 'white';
}
}
}
Logger.log("done");
colourRange.setBackgrounds(colours);
}
When debugging my colourRangeVals has an array of 31 with 10 columns. My colours array has an array of 31 with 10 columns but I still get the above error.
Any ideas??
Thanks
The issue may be caused by the first for loop that starts iteration from 1 instead of 0.
To see the results in the spreadsheet and so make debugging easier, try replacing the last line of code with this:
colourRange.offset(0, 0, colours.length, colours[0].length).setBackgrounds(colours);
I am making a game in flash and my only problem so far is this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at farmgame227_fla::MainTimeline/onenter()[farmgame227_fla.MainTimeline::frame2:144]
The line will vary depending on how I move to the next frame. I am 99% sure a null object is not the problem, so I am stumped. I will show my entire code for frame 2 and I would appreciate it so much if anyone could lend some insight.
stop();
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,onenter);
stop();
//starting positions for sheep
sheep1.y = 330
sheep1.x = 350
sheep2.y = 360
sheep2.x = 380
sheep3.y = 300
sheep3.x = 450
sheep4.y = 330
sheep4.x = 350
gold.y = 150
gold.x = 800
goat.y = 620
goat.x = 800
var myscore = 0;
function onenter(e:Event)
{
//hand follows mouse cursor
hand.x = mouseX;
hand.y = mouseY;
//sheep velocity
sheep1.x = sheep1.x + 1;
sheep1.y = sheep1.y - 1;
sheep2.x = sheep2.x - 1;
sheep2.y = sheep2.y - 1;
sheep3.x = sheep3.x + 1;
sheep3.y = sheep3.y + 1;
sheep4.x = sheep4.x - 3;
sheep4.y = sheep4.y + 3;
//sheep1's boundaries
if (sheep1.y < 0 || sheep1.y > 775 || sheep1.x < 0 || sheep1.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//sheep2's boundaries
if (sheep2.y < 0 || sheep2.y > 775 || sheep2.x < 0 || sheep2.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//sheep3's boundaries
if (sheep3.y < 0 || sheep3.y > 775 || sheep3.x < 0 || sheep3.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//sheep4's boundaries
if(sheep4==null)
{
trace("4 it's null");
}
if (sheep4.y < 0 || sheep4.y > 775 || sheep4.x < 0 || sheep4.x > 775)
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//hand hitting sheep, sending them back
if(sheep1==null)
{
trace("1 is null");
}
if(hand==null)
{
trace("hand is null");
}
if(fence==null)
{
trace("fence is null");
}
if (hand.hitTestObject (sheep1))
{
sheep1.y = 330;
sheep1.x = 350;
myscore = myscore + 1;
}
if (hand.hitTestObject (sheep2))
{
sheep2.y = 360;
sheep2.x = 380;
myscore = myscore + 1;
}
if (hand.hitTestObject (sheep3))
{
sheep3.y = 300;
sheep3.x = 450;
myscore = myscore + 1;
}
if (hand.hitTestObject (sheep4))
{
sheep4.y = 330;
sheep4.x = 350;
myscore = myscore + 1;
}
if (hand.hitTestObject (gold))
{
gold.x = 2500;
gold.y = 610;
gold.x = gold.x - 9;
myscore = myscore + 5;
}
if (hand.hitTestObject (goat))
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
//hand touching fence, results in game over
if (hand.hitTestObject (fence))
{
removeEventListener(Event.ENTER_FRAME,onenter);
nextFrame();
}
score.text = myscore;
//changing sheep speed based on score
//score 40 and 55 should be next
if (myscore >= 12)
{
sheep2.x = sheep2.x - 2;
sheep2.y = sheep2.y - 2;
}
if (myscore >= 24)
{
sheep3.x = sheep3.x + 2;
sheep3.y = sheep3.y + 2;
}
if (myscore >= 30)
{
sheep1.x = sheep1.x + 3;
sheep1.y = sheep1.y - 3;
}
//initiating and controlling gold and goat
if (myscore > 17)
{
gold.x = gold.x - 8;
}
if (gold.x < -9)
{
gold.x = 2000;
gold.y = 610;
gold.x = gold.x - 9;
}
if (myscore > 8)
{
goat.x = goat.x - 3;
}
if (goat.x < -9)
{
goat.x = 1600;
goat.y = 150;
goat.x = goat.x - 4;
}
}
You should shift all the checks in onenter upwards, prior to assigning anything to either sheep or other objects. Then you will likely find that one of the objects is null. The #1009 error means that some object reference that's placed right before a "." qualifier is null, and you can't get properties out of nothing.
Also, try placing return right after any call of nextFrame(), because when you perform nextframe, the previous frame's vars are invalidated, thus you can't refer to say hand because there's no more hand, it's destroyed along with the whole previous frame.
I am new to Flash AS3 and I have seen this code online but its coded in AS2 can anyone help me.
onClipEvent (enterFrame)
{
distance = _root.enemy._x - _root.player._x;
if (distance < 100 && distance > -100 && _root.enemyTimer == 0)
{
a = int(Math.random() * 100);
if (a >= 0 && a < 60)
{
_root.enemy.gotoAndStop('attack1');
_root.healthbar.gotoAndStop(_root.healthbar._currentframe -= 5);
}
else if (a >= 60 && a <= 100)
{
_root.enemy.gotoAndStop('attack2');
_root.healthbar.gotoAndStop(_root.healthbar._currentframe -= 8);
}
}
if (distance < 160 && distance > 100)
{
this._xscale = _root.eScale;
_x -= 2;
}
if (distance > -160 && distance < -100)
{
this._xscale = -_root.eScale;
_x += 2;
}
}
tnx in advance I'll be using this as a reference.
this.addEventListener(Event.ENTER_FRAME, functionName);
function functionName(e:Event):void
{
var distance:Number = this.enemy.x - this.player.x;
if (distance < 100 && distance > -100 && this.enemyTimer == 0)
{
var a:int = int(Math.random() * 100);
if (a >= 0 && a < 60)
{
this.enemy.gotoAndStop('attack1');
this.healthbar.gotoAndStop(this.healthbar.currentFrame -= 5);
}
else if (a >= 60 && a <= 100)
{
this.enemy.gotoAndStop('attack2');
this.healthbar.gotoAndStop(this.healthbar.currentFrame -= 8);
}
}
if (distance < 160 && distance > 100)
{
this.scaleX = this.eScale;
this.x -= 2;
}
if (distance > -160 && distance < -100)
{
this.scaleX = -this.eScale;
this.x += 2;
}
}
i want to put gradient masking effect in my 20 images.
var arr:Array = ["m1.jpg","m2.jpg","m3.jpg","m4.jpg","m5.jpg"];
for(var i=0; i<20; i++){
duplicateMovieClip(ho, "newImg_mc"+i , this.getNextHighestDepth());
if(i < 5){
this["newImg_mc"+i]._x = 0;
this["newImg_mc"+i]._y = 110*i;
this["newImg_mc"+i].loadMovie(arr[i]);
}
if(i >= 5 and i < 10){
this["newImg_mc"+i]._x = 110;
this["newImg_mc"+i]._y = 110*(i-5);
this["newImg_mc"+i].loadMovie(arr[i-5]);
}
if(i >= 10 and i < 15){
this["newImg_mc"+i]._x = 220;
this["newImg_mc"+i]._y = 110*(i-10);
this["newImg_mc"+i].loadMovie(arr[i-10]);
}
if(i >= 15 and i < 20){
this["newImg_mc"+i]._x = 330;
this["newImg_mc"+i]._y = 110*(i-15);
this["newImg_mc"+i].loadMovie(arr[i-15]);
}
}
you need to set the blendMode of the mask and the masked object to BlendMode.LAYER.