Script Error: Cannot cast 'array' to listener

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
AIC
Private
Posts: 4
Joined: Mon Jul 01, 2002 3:07 pm
Location: Almere, The Netherlands
Contact:

Script Error: Cannot cast 'array' to listener

Post by AIC »

What does this error mean?

Code: Select all

	local.bomb_offset = 	local.bomb.origin - 	local.base.origin  (maps/obj/mainobj.scr, 61)
	local.bomb_offset = 	local.bomb^
Script Error: Cannot cast 'array' to listener
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

usually when you see this error it is because you are trying to cast an array of something that is a single entity . It is because you need braces around it

local.bomb_offset = (local.bomb.origin - local.base.origin )

local.bomb_offset = local.bomb.origin - local.base.origin

what you did is try to make local.offset and local.bomb.origin an array without the braces it does not do the subrataction untill after it has done the local.bomb_offset = local.bomb.origin , in affect makeing two local.bomb.origins if you had said local.bomb_offset.origin = local.bomb.origin it may have worked if local.bomb_offset was an entity that you could give an origin to , as it is local.bomb_offset is a number you can not giva a coordinate to and local.bomb.origin is a position from which you can calculate a vector length from another origin
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

after reading what I wrote I realized that I did not make it exacly clear you see local.bomb.origin is actully an array with 3 elements a x coordinate a y coordinate and a z coordinate where as local.bomb_offset is a single entity .

Here I go again you ask a question and I write a story haha any way put in the braces
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

I think local.bomb is an array. As an array can never have one origin, you get this error message.

I'm sorry bdbodger but what you are saying just isn't correct.
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

sorry jv what you said makes no sense . As an array can never have one origin? I guess you mean is one element . that is not true .

local.bomb_offset[1]= 10 is a one element array until you set local.bomb_offset[2]

local.bomb_offset = local.bomb.origin - local.base.origin (maps/obj/mainobj.scr, 61)
local.bomb_offset = local.bomb^
Script Error: Cannot cast 'array' to listener

local.bomb_offset is the listener and local.bomb.origin is a 3 element array to make local.bomb_offset an array you need to either use the .origin at the end of it to automaicatly make it a vector array or use this format

local.bomb_offset= hello::world::this::is::a::test::123 // consant array
or
local.bomb_offset= (10 -2 60.1) // vector

or cast a single value to it like this

local.bomb_offset[1]= 10

here is some lines from the spript documentation in mohradiant

Vectors are accessed like arrays in the indices 0, 1, 2.
A vector could be set like
local.my_vector = (10 -2 60.1)

Then this vector could be accessed like:
println local.n[2]
which would print 60.1 to the console.

normaly an array starts it's indexing at 1 but a vector starts at 0
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

sorry jv what you said makes no sense . As an array can never have one origin? I guess you mean is one element . that is not true .
Please state my words are wrong instead of changing my words and then prove them wrong ;).

I know an array can have one element, although then it's not really an array anymore. The problem is, that an array of multiple elements can't have one origin, but needs an origin for every element (listeners in this case).
local.bomb_offset is the listener and local.bomb.origin is a 3 element array to make
No. local.bomb is an array but should be a listener, like the error message says. Arrays can not have variables like listeners can, so .origin is not allowed. In fact you need to define a listener, which is probably an element of the local.bomb array.

Example:
local.bomb[1].origin

Rest of your post is slightly off-topic :roll:.
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

I think I can follow what you are saying but

Script Error: Cannot cast 'array' to listener

hmm "cast array" hmm sounds to me like it is trying to "cast array" to some thing that is not an array or "cast array" to a single entinty or listener . o well I will chew on it for a while and see if I can swollow it or not .
P.S. I know you have been a lot of help to a lot of people includeing me so keep up the good work and thanks
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Script Error: Cannot cast 'array' to listener

The game tries to cast something (an array) to a listener, but it cannot turn an array into a listener. :)

Does that make sense?
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

well still in a fog about the whole thing . So you mean "cast" is to make into . To create or convert into , not as in to give multiple values to listener . How do you define a listener ? . I think I am getting stuck on the terms used .
The problem is, that an array of multiple elements can't have one origin, but needs an origin for every element (listeners in this case).
This confuses me too how do you define an origin ? I think of it as 3 numbers that specify a position in the game . Well if you can clear all this up for me I might ask you about vectors next hahaha .
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

A listener is anything that can hold variables. Things like entities are listeners. Also script threads are listeners (local, group), the world ($world) and both level and game. An array is not a listener, so it can't have variables.

Say you have this array (as variable for the 'local' listener):
local.array = $mybomb::$yourbomb

Then local.array can never have any variables:
local.array.exploded or local.array.origin don't exist.

In this case the array consists of listeners, so elements of the array can have variables:
local.array[1].origin
or
local.array[2].origin

An origin is a vector that's used by the game as the position to place a given entity. Origin is a variable that's a property of any entity. You cannot modify parts of an origin but only set a new origin.

For example:
$mybomb.origin[2] = 50
would not work, you need to define the origin as a whole:
$mybomb.origin = ($mybomb.origin[0] $mybomb.origin[1] 50)

Maybe this helps somehow. Don't worry - you can ask anything if I'm not clear though ;).
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

ok I read the documentation in the SDK and it finaly clicked . I am so use to just placeing things in the editor I tend to think of things in terms of a grid . It has been a lot of years since high school but I feel I have just had a refreasher . Now I see that an origin is a single point in 3 demensional space and I understand the offsets used in the game a lot better . So back to the beginning of the thread was aic trying to find the vector length between the two points .
local.bomb_offset = local.bomb.origin - local.base.origin
and what is the syntax for that is it local.bomb_offset = vector_length ( local.bomb.origin local.base.origin ) . or was he looking for how far above it it was or far to the left or right or infront or in back of it was . Any way thanks for crearing that up . I think I may have a grasp on it now .
Post Reply