Computer Science Canada

[FIXED]reating a flexible array of objects

Author:  viperfan7 [ Mon Mar 18, 2013 11:40 am ]
Post subject:  [FIXED]reating a flexible array of objects

I was using the new statement wrong, fixed it now



What is it you are trying to achieve?
Trying to convert the GravArt.t example to use objects and have a variable planet count, just doing this for the fun of it


What is the problem you are having?
I'm having issues figuring out how to store objects into a flexible array, all it does is error out with subscript of planetsArray is of wrong type


Describe what you have tried to solve this problem
I've tried creating a junk variable of type ^PlanetClass and using new planetsArray, junkvar


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


var planetsArray : flexible array 1 .. 0 of ^PlanetClass
...
...
...
    for i : 1 .. planetCount
        new planetsArray , PlanetClass
    end for



Please specify what version of Turing you are using
Using whatever the version of OpenTuring is, the one with the nice editor

Author:  Raknarg [ Mon Mar 18, 2013 12:18 pm ]
Post subject:  RE:[FIXED]reating a flexible array of objects

Ok, it's because you're stating things wrong.

If you want to change the upper value of a flexible array, you do this:

var arr : flexible array 1 .. 0 of int
new arr, 5

That will change the upper limit to 5.


If you want to state a new class, you do this:

var classVariable : ^Class
new Class, classVariable


Now lets put them together:

var arrClass : flexible array 1 .. 0 of ^Class
new arrClass, 1
new Class, arrClass (1)


Also note the feature upper, which results the upper bound of an array

Author:  viperfan7 [ Mon Mar 18, 2013 12:37 pm ]
Post subject:  Re: [FIXED]reating a flexible array of objects

Figured it out just after I had posted it, now have it fully functional, been years since I've done anything in turing, been coding in C# as of late


: