'Not A Member of Object' Error - unity3d

I think I'm beginning to like this coding stuff. Anyway in my current Shooting Gallery project I have a JavaScript question. I'm building in Unity3d and I get a "transform" is not a member of "Object" error on the code inserted below.
var newball;
static var tempBasketBall :Rigidbody;
private var canFire = true;
var pos :Transform[];
var ball1 :Rigidbody;
var canControl1 = true;
var destroyTime :int = 6;
var player1 :GameObject;
var b1Parent :Transform;
var yVel :float;
var zVel :float;
function Start()
{
ball1 = Instantiate (tempBasketBall, pos[0].position, pos[0].rotation);
ball1.transform.parent = b1Parent;
}
function Update() {
if(Input.GetButton("Fire1"))
animation.PlayQueued("fire", QueueMode.PlayNow);
}
function TapFunction() {
animation.PlayQueued("fire", QueueMode.PlayNow);
player1.animation.PlayQueued("fire");
ball1.transform.parent = null;
ball1.useGravity = true;
ball1.velocity = transform.TransformDirection(0, yVel, zVel);
MakeBall1(pos[0]);
canControl1 = false;
player1.animation.PlayQueued("idle");
}
function MakeBall1(pos)
{
yield new WaitForSeconds(1);
ball1 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation);
ball1.transform.parent = b1Parent;
canControl1 = true;
}
The error is in the MakeBall function at the end. To my untrained mind, it seems I established the
transform in the start function. As usual any assistance and shared knowledge will be tremendously appreciated.

Transform(you are passing as argument an onject of this tipe) does not have a "transform" member,you should use pos.position

Related

Expressions in statements must only be executed for their side effects

I'm having a rather unusual problem with this code in unity, I keep getting the error "Expressions in statements must only be executed for their side-effects", I went around the web searching for the problem but all the answers were different, the line that is giving the error is (47,44) which is the AnimObj.GetComponent.<Animation>().Play thanks in advance for the help -_-;
var CrossObject : GameObject;
var MechanicsObject : GameObject;
var ClipCount : int;
var ReserveCount : int;
var ReloadAvailable : int;
var AnimObj : GameObject;
var ScriptObj : GameObject;
function Update () {
ClipCount = GlobalAmmo.LoadedAmmo;
ReserveCount = GlobalAmmo.CurrentAmmo;
if (ReserveCount == 0) {
ReloadAvailable = 0;
} else {
ReloadAvailable = 10 - ClipCount;
}
if (Input.GetButtonDown("Reload")) {
if (ReloadAvailable >=1) {
if (ReserveCount <= ReloadAvailable) {
GlobalAmmo.LoadedAmmo += ReserveCount;
GlobalAmmo.CurrentAmmo -= ReserveCount;
ActionReload();
} else {
GlobalAmmo.LoadedAmmo += ReloadAvailable;
GlobalAmmo.CurrentAmmo -= ReloadAvailable;
ActionReload();
}
}
EnableScripts();
}
}
function EnableScripts () {
yield WaitForSeconds(1);
ScriptObj.GetComponent("Fire").enabled=true;
CrossObject.SetActive(true);
MechanicsObject.SetActive(true);
}
function ActionReload () {
ScriptObj.GetComponent("Fire").enabled=false;
CrossObject.SetActive(false);
MechanicsObject.SetActive(false);
AnimObj.GetComponent.<Animation>().Play;
}
In Unity, Animation.Play() is a function not a variable. You are accessing that as a variable by not including () at the end of Play.
It should be:
AnimObj.GetComponent.<Animation>().Play();

CreateJS swapping display list containers with the use of classes

This is a 2D Jenga game.
So I am currently making a Jenga game in createjs. When users take a block out from the Jenga building they can move it around, ultimately users are suppose to be able to take the piece and move it to the top like a typical Jenga game. The problem is you can take any piece out move it towards the bottom it appears to be in front of the Jenga building, but once you move a block towards the top it goes behind the building. I have a piece class which creates one block looks like this:
var GamepeiceComponent = (function() {
var assets = {};
var offset;
var gamePeice;
var currentX;
var currentY;
var newContainer;
this.makePiece = function(ingredient) {
gamePeice = new createjs.Container();
assets.peice = new createjs.Bitmap(queue.getResult(ingredient));
gamePeice.on('pressmove', handlePieceDrag);
gamePeice.on("pressup", handlePieceUp);
gamePeice.on("mousedown", handleMouseDown);
gamePeice.cursor = 'pointer';
gamePeice.addChild(assets.peice);
}
function handleMouseDown(e) {
// Game.block.swapChildren(e.currentTarget, Game.block);
for(var i = 0; i < Game.stage.children.length; i++){
console.log(Game.stage.children[i]);
//Game.stage.swapChildren(e.currentTarget, Game.stage.children[i])
}
//Game.stage.addChildAt(gamePeice,1);
offset = {x: e.target.x - e.stageX, y: e.target.y - e.stageY};
createjs.EventDispatcher.initialize(GamepeiceComponent.prototype);
gamePeice.dispatchEvent("pieceClicked");
}
function handlePieceDrag(e) {
e.target.x = e.stageX + offset.x;
e.target.y = e.stageY + offset.y;
}
function handlePieceUp(e) {
e.target.x = 0;
e.target.y = 0;
}
this.addPiece = function() {
return gamePeice;
}
return this;
});
I then have a block class which creates a block using the piece class because it creates 3 pieces per block (just like Jenga) heres what that is:
var GameblockComponent = (function() {
var gameBlock;
this.makeBlock = function(ingredient, yOffset, xOffset) {
gameBlock = new createjs.Container();
for(var i=0;i<3;i++) {
var gamePieces = new GamepeiceComponent();
var makePiece = gamePieces.makePiece(ingredient);
gamePieces.addPiece().y = yOffset * i;
gamePieces.addPiece().x = xOffset * i;
gamePieces.addPiece().on('pieceClicked', handleClick);
gameBlock.addChild(gamePieces.addPiece());
}
}
function handleClick(e) {
console.log('Game Piece Clicked');
}
this.addBlock = function() {
return gameBlock;
}
return this;
});
Lastly I have a building which organizes all the blocks in order:
var GamebuildingComponent = (function(game) {
var jengaContainer;
var left = ['burger_l', 'cheese_l', 'egg_l', 'ham_l', 'lettuce_l', 'onion_l', 'pickle_l', 'salmon_l', 'sausage_l', 'tomato_l'];
var right = ['burger_r', 'cheese_r', 'egg_r', 'ham_r', 'lettuce_r', 'onion_r', 'pickle_r', 'salmon_r', 'sausage_r', 'tomato_r'];
var bread = ['bread_l', 'bread_r'];
var seed = [];
var offsets = {
xOffsetLeft: 15,
yOffsetLeft: -33,
xPosLeft: 170,
xOffsetRight: 17,
yOffsetRight: 33,
yPosRight:100
};
function init() {
jengaContainer = new createjs.Container();
createBread(15);
createSubBlock(40);
createBread(160);
createSubBlock(185);
createBread(305);
}
function createBread(yOffset) {
var block = new GameblockComponent();
var breadLeft = block.makeBlock(bread[0], offsets.xOffsetLeft, offsets.yOffsetLeft);
block.addBlock().x = 170;
block.addBlock().y = yOffset;
jengaContainer.addChildAt(block.addBlock(), 0);
}
// LEFT: left side facing to left
// RIGHT: right side facing to right
function createSubBlock(yOffset) {
for(var i=0;i<5;i++) {
var block = new GameblockComponent();
var random = Math.floor(Math.random()*left.length);
// prevents duplicates
while(seed.indexOf(random) > -1) {
var random = Math.floor(Math.random()*left.length);
}
if(i%2 != 0) {
var ingredient = block.makeBlock(left[random], offsets.xOffsetLeft, offsets.yOffsetLeft);
block.addBlock().x = 170;
} else {
var ingredient = block.makeBlock(right[random], offsets.xOffsetRight, offsets.yOffsetRight);
block.addBlock().x = 105;
}
seed.push(random);
block.addBlock().y = 23 * i + yOffset;
jengaContainer.addChildAt(block.addBlock(), 0);
}
}
this.addBuilding = function() {
return jengaContainer;
}
init();
return this;
});
It all works fine except for when you move a lower piece towards the top the piece goes behind the jenga building, and of course its how the displaylist works, how would I be able to swap the piece correctly and where? I was listing all my child elements that are on the stage and it gave me one child (the jenga building). That child gave me 13 children (each block).
Then I just add the Jenga building to a view, and that view gets called from a controller.
You're probably looking for the setChildIndex method of the Container object.
function handleMouseDown(e) {
Game.block.setChildIndex(e.currentTarget, Game.block.children.length - 1);
}

Not able to retrieve callback parameters

var arr = [1,2,3,4,5,6];
Array.prototype.filter2 = function(){
var fir = arguments[0];
var sec = arguments[1];
alert(fir);
alert(sec);
var arr2 = new Array();
for(var item=0; item<this.length;item++){
alert(this[item]); // 1 section
if(sec.call(this[item],fir)){
arr2.push(this[item]);
}
}
return arr2;
}
function xyz (ele ,x){
alert(x);
alert(ele);
return ele > x;
}
arr.filter2(2,xyz);
Till 1'st its running fine but while passing the argument to the callback... x is being alerted as "undefined" whereas ele = fir
Your answer is simple and straight:
either call your function normally,.. i.e
Array.prototype.filter2 = function(){
var fir = arguments[0];
var sec = arguments[1];
alert(fir);
alert(sec);
var arr2 = new Array();
for(var item=0; item<this.length;item++){
alert(this[item]); // 1 section
if(sec(this[item],fir)){
arr2.push(this[item]);
}
}
return arr2;
}
Or if you still want to stick with javascript .call(), then simply use it like this:
Array.prototype.filter2 = function(){
var fir = arguments[0];
var sec = arguments[1];
alert(fir);
alert(sec);
var arr2 = new Array();
for(var item=0; item<this.length;item++){
alert(this[item]); // 1 section
if(sec.call({},this[item],fir)){
arr2.push(this[item]);
}
}
return arr2;
}
call() and apply() are predefined JavaScript function methods. Both methods can be used to invoke a function, and both methods must have the owner object as first parameter.
You can read more about this by clicking here and find it under heading Invoking a Function with a Function Method

How make a Level Unlocker using GUI Buttons and PlayerPrefs things?

#pragma strict
var challenge1 : Texture;
var challenge2 : Texture;
var challenge3 : Texture;
var LevelOneEnabled = true;
var LevelTwoEnabled = false;
var LevelThreeEnabled = false;
var Score : TextMesh;
var Score2 : TextMesh;
var Score3 : TextMesh;
function Start(){
}
function Awake(){
Score.text = "Highscore: "+ PlayerPrefs.GetInt("JeepneyScore");
Score2.text = "Highscore: "+ PlayerPrefs.GetInt("JeepneyScore2");
Score3.text = "Best Time: "+ PlayerPrefs.GetFloat("JeepneyScore3");
}
function OnGUI()
{
GUI.enabled = LevelOneEnabled;
if(GUI.Button(Rect(400,100,250,250),challenge1)){
Application.LoadLevel("LoadScene");
}
GUI.enabled = LevelTwoEnabled;
if(GUI.Button(Rect(700,100,250,250),challenge2)){
Application.LoadLevel("LoadScene2");
}
GUI.enabled = LevelThreeEnabled;
if(GUI.Button(Rect(1000,100,250,250),challenge3)){
Application.LoadLevel("LoadScene3");
}
}
Can anybody knows hot to get the logic in playerprefs so that the LoadScene2, and 3
will unlock after finishing the first mission?
Please I'm hoping for an answer :(
put in
var level : int;
then in start
level = PlayerPrefs.GetInt("level",0);
then in your if(GUI.Buttons){}
if(level >= 2){}
and
if(level >= 3){}
and so on and in your actual levels set the int in your playerprefs once they complete the level, probably load the int again and use if to check if it is greater than then replace if it is not
EDIT:
var levelnum : int = 2;
PlayerPrefs.SetInt("level",levelnum);

Google apps script listbox event processing, undefined value

The idea of this apps script is to populate listbox LbxJobs based on the selected item in listbox LbxJobTypes.
I am getting an undefined value for e.parameter.LbxJobType which seems to be preventing conditional population of LbxJobs.
I successfully tested the handler(JobTypeValueHandler) by hard coding(I set JobType=T300_JOB_TYPE) JobTypeValueHandler function and the LbxJobs listbox populated as expected.
I do get "LbxJobType" when checking e.parameter.source. The listboxes were created in GUI builder.
var T200_JOB_TYPE = 1;
var T300_JOB_TYPE = 2;
function doGet() {
var app = UiApp.createApplication();
app.add(app.loadComponent("BasicCalculator"));
var Dischandler = app.createServerHandler('DiscClickHandler');
app.getElementById('chbxDiscl').addValueChangeHandler(Dischandler);
return app;
}
function DiscClickHandler(e) {
var app = UiApp.getActiveApplication();
var Discpanel = app.getElementById('FLpnlDisc');
BCalcSetup(app);
Discpanel.setVisible(false);
return app;
}
function BasicClickHandler(e) {
var app = UiApp.getActiveApplication();
return app;
}
function BCalcSetup(app){
var BCalcpanel = app.getElementById('APnlBCalc');
var lbxJobType = app.getElementById('LbxJobType');
var JobTpyehandler = app.createServerChangeHandler('JobTypeValueHandler');
var lbxJobs = app.getElementById('LbxJobs');
JobTpyehandler.addCallbackElement(lbxJobType);
lbxJobType.addChangeHandler(JobTpyehandler);
lbxJobType.addItem('Title 200');
lbxJobType.addItem('Title 300');
loadClassifications(lbxJobs,T200_JOB_TYPE);
BCalcpanel.setVisible(true);
}
function JobTypeValueHandler(e) {
var app = UiApp.getActiveApplication();
var JobType=T200_JOB_TYPE;
var lboxJobs=app.getElementById('LbxJobs');
if (e.parameter.LbxJobType=='Title 300'){JobType=T300_JOB_TYPE;}
loadClassifications(lboxJobs,JobType);
app.close();
return app;
}
function loadClassifications(lbox,JobType){
var spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
lbox.clear();
if (JobType==T300_JOB_TYPE){
var T3data =spreadsheet.getRangeByName('Title300Jobs').getValues();
for (var row1 = 1; row1 < T3data.length; row1++) {
lbox.addItem(T3data[row1]);
}
}else{
var T2data =spreadsheet.getRangeByName('Title200Jobs').getValues();
for (var row2 = 1; row2 < T2data.length; row2++) {
lbox.addItem(T2data[row2]);
}
}
}
I feel kind of silly but I figured this out. The problem I had was I did not fill in the Name property for these listboxes when I created the interface in GUI builder. I went back into GUI builder and filled in the name property for each box and and now it works like a champ. Live and learn