I'm currently experimenting with OOP J. Creating objects and playing with 
them.This is my code:
NB. My class def
coclass 'GameObject'      px =: 0   py =: 0   pz =: 0      movex =: 3 : 'px =: 
y'      destroy =: codestroy
NB. lets make instances and play.
cocurrent 'base'     go =: conew 'GameObject'
px__go
0 NB. returned 0, that is what I expected!
NB. move the px value...
movex__go 5
5   px__go
5 NB. again this is what I expect.
NB. create a list of GameObjects...
list =: 5 $ conew 'GameObject'  NB. I don't understand the output here. list
┌─┬─┬─┬─┬─┐│2│2│2│2│2│└─┴─┴─┴─┴─┘
NB. anyway let's at least try to get a hold of one of the objects.
go =. 0{list   px__go
0 NB. Wow, it worked!
   movex__go 5
5   px__go
5   go2 =: 1{list   px__go2
5

The very end, "px__go2" is troubling, because this object's px value is 5! The 
only way this can be is if(a) 1{list and 0{list somehow point to the same 
object,(b) px is a static variable.
I'm going to guess (a), but I would like to know what is going on here.

Secondly, in my object definition, I would like to have a "create" verb which 
does the following:

create_go  1 4 5

this will set px to 1, py to 4 and pz to 5. I'm not sure how to do multiple 
assignments in J with on function.
I think if it wasn't a class function I could do (for three arbitrary variables)


'px py pz' =: 3 NB. sets all vars to 3, not really what I want, but it's a 
start.

or something like that, but for class functions I don't know how to do this. 
Any help appreciated.
Regards.                                          
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to