About Monkey 2 › Forums › Monkey 2 Programming Help › Inside access
This topic contains 3 replies, has 2 voices, and was last updated by
Gwenel
12 months ago.
-
AuthorPosts
-
April 22, 2018 at 12:14 pm #14460
This got more lots more tricky than I thought it would, but how do you access x y z inside enemy?
I need to do it both xyz all at once as a combined (Vec3?), and z alone (int).Monkey123456789101112131415161718192021222324252627282930313233Namespace myapp#Import "<std>"Using std..Function Main()Local somearray2 := New enemy[10]For Local i:Int=0 Until 10somearray2[i] = New enemyNextsomearray2[3].px = 100 ' Works perfectly' somearray2[3].position.x = 100 ' Why crash? Do you need to init something?' somearray2[3].position = Vec3(1,2,3) ' How do you match types? (want to set .x .y .z at once) Is it possible for example to match the inbuild vector type and a handmade vector type? if not how can you access a hand made one like this inside enemy here?EndClass vectorField x : IntField y : IntField z : IntEndClass enemyField px : IntField py : IntField name : StringField position:vectorField speed:vectorField acceleration:vectorEndApril 22, 2018 at 2:05 pm #14464You want somearray2[3].position.x
Oh, wait, you also need to init the vector, so somearray2[3].position = New vector, follow by somearray2[3].positionx = whatever
Or, in your loop…
[/crayon]Monkey123456789101112[crayon-5cb9db817fd04164323077 inline="true" ]Local somearray2 := New enemy[10]For Local i:Int=0 Until 10somearray2[i] = New enemysomearray2[i].position = New vectorsomearray2[i].position.x = 100 ' etcNextApril 22, 2018 at 5:06 pm #14466Thanks Okay got everything working except the last part now. How to make it possible to send x y z all at once in some way (using vector or vec3 altogether instead of using the vector class, both solutions would be interesting to hear about
Monkey12345678910111213141516171819202122232425262728293031323334Namespace myapp#Import "<std>"Using std..Function Main()Local somearray2 := New enemy[10]For Local i:Int=0 Until 10somearray2[i] = New enemyNextsomearray2[3].px = 100 ' Works perfectlysomearray2[3].position = New vectorsomearray2[3].position.x = 100 ' Works perfectly' somearray2[3].position = Vec3(1,2,3) 'This one is still a mystery' somearray3[3].position = Vector(100,100,100) ' Wishing for something that looks like one of these twoEndClass vectorField x : IntField y : IntField z : IntEndClass enemyField px : IntField py : IntField name : StringField position:vectorField speed:vectorField acceleration:vectorEndApril 23, 2018 at 4:46 am #14479Getting there…
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748Namespace myapp#Import "<std>"Using std..Function Main()' Create array of custom typeLocal somearray2 := New enemy[10]For Local i:Int=0 Until 10somearray2[i] = New enemyNext' Access it in different wayssomearray2[3].px = 100 ' Works perfectlysomearray2[3].position = New vectorsomearray2[3].position.x = 100 ' Works perfectlysomearray2[3].position2 = New Vec3<Int>(-1,-1,-1) ' Works perfectly' Still to do is to find some way to use a home-made vector and not access just x y z separate but as a group similar to the above'' somearray3[3].position = Vector(100,100,100) ' Is it possible to fill ALL fields of a class? And maybe use ,, to skip fields?EndClass vectorField x : IntField y : IntField z : IntEndClass enemyField px : IntField py : IntField name : String' Using home-made vector type (needs work)Field position:vectorField speed:vectorField acceleration:vector' Using pre-made vector typeField position2:Vec3<Int>Field speed2:Vec3<Int>Field acceleration2:Vec3<Int>End -
AuthorPosts
You must be logged in to reply to this topic.