Author Topic: brick value won't let me call a function?  (Read 2031 times)

Hello, I am using a double for loop to get a brick from the master brick group. And I am using %brick as my variable, it exists since when I echo it I get a number.

I then store it in an array using if it meets the criteria (It's for a spawn brick) $AnArrayName.add(%brick);

And then at the end I do return $AnArrayName[%randomnumthatisinrange].getSpawnLocation();

getSpawnLocation is a function I've added like this:
Code: [Select]
function fxDTSBrick::getSpawnLocation() {
        //insert code here to work out %endvalue
        return %endvalue;
}

But the console spits out an error saying I am attempting to call function getSpawnLocation on ''

Any ideas?

You need to put %this in the arguments for the function. If it's a default function then you need to package it, as well, though I'm not sure if that's default.

You need to put %this in the arguments for the function. If it's a default function then you need to package it, as well, though I'm not sure if that's default.

Thanks I'll try that!

And no it's not a default function:)

Ok I tried it, still doesn't work though.

I found another problem is that my array $spawnBricksList doesn't exist when the line get's executed? Do array's disappear when there's no value or something?

Ok I tried it, still doesn't work though.

I found another problem is that my array $spawnBricksList doesn't exist when the line get's executed? Do array's disappear when there's no value or something?
Well uh, I noticed you're calling $AnArrayName.add(%brick);, what exactly is $AnArrayName? Is it an object that has the function add? If so, you probably need to use .getObject(%index), not $AnArrayName[%index].

Is it an object that has the function add? If so, you probably need to use .getObject(%index), not $AnArrayName[%index].
I thought arrays were objects in torquescript?

I thought arrays were objects in torquescript?
Nope, they're just replacements for variable names. %a[5] ≡ %a5
« Last Edit: January 19, 2015, 11:13:24 AM by Ipquarx »


Thanks for your help guys, If you want to know the fix I just did a for loop and checked for empty array slots, if it was empty then it adds it and breaks the loop. Since .add doesn't work like Ipquarx pointed out.

A better solution might be to add all of the bricks to a SimSet.

Code: [Select]
$mySimSet = new SimSet();
$mySimSet.add($myBrick);
$randomBrick = $mySimSet.getObject(getRandom(0, $mySimSet.getCount() - 1));


disgusting
I wanted to use ≡ which means "by definition equals" if i remember correctly, but I was too lazy to look up the symbol.

I wanted to use ≡ which means "by definition equals" if i remember correctly, but I was too lazy to look up the symbol.
ah, I thought you were using Javascript's identity operator