Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology
Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered
You are not logged in.
I point out the problem at the comments. Basically, I try to fill a list of table of custom objects (struct type QRSCoordinate) within another object (struct type Hexagon). The property name of the table of customs objects is lqrspoints. In the code below, when I try to fill up this table, the values are not saved in it. The code will show more of what I am trying to say.
here are the comments in the code pasted below which point out where the problem is:
//load created vertex into hex.lqrspoints table for the hex object that called this function
//something is not working here:
,
//test to see if hex.lqrspoints has been filled, as per console, it remains empty, and
//the console doesn't display any value for firstpoint.posq
here is the full code
typeof hexvqrsvectors= tab[I I I];;
struct XYVertex=[
posx: I,
posy: I
]mkXYVertex;;//this makes a vertex object with xy coordinates
struct QRSCoordinate=[
posq: I,
posr: I,
poss: I
]mkQRSCoordinate;;//this makes a vertex object with qrs coordinates. It is easier to create a grid
//of hexagons this way and you can use xyz vector functions with your hexagons
struct Hexagon=[
VQRScenter: QRSCoordinate,
Isize: I,
lxypoints: tab XYVertex,
lqrspoints: tab QRSCoordinate,
funcwithinbounds: fun [[Hexagon XYVertex]] I,
funmakeqrsvertices: fun [Hexagon] [tab QRSCoordinate],
funconvert_xy_to_qrs: fun [Hexagon][I I I],
funconvert_qrs_to_xy: fun [Hexagon][I I]
]mkHexagon;;
//this object will hold a bunch of hexagons in a grid in qrs coordinate system
//this will be very important to build a hexagon grid with hexagon .mesh object in os3d i think
struct Hexagongrid=[
hexagongrid: [Hexagon r1]
] mkHexagongrid;;
fun createqrshexvectors(hex)=
set hexvqrsvectors = mktab 6 nil;
set hexvqrsvectors.0= [1 (-1) 0]; //EAST VECTOR
set hexvqrsvectors.1=[1 0 (-1)];//northeast vector
set hexvqrsvectors.2=[0 1 (-1)];//northwestvector
set hexvqrsvectors.3=[(-1) 1 0];//west vector
set hexvqrsvectors.4=[(-1) 0 1];//southwestvector
set hexvqrsvectors.5=[0 (-1) 1];//southeast vector
hexvqrsvectors;;
fun definedfunconvert_xy_to_qrs(hexagon) =
[0 0 0 0];;
fun create_vertex_qrscoordinates(hex)=
//create vertices in sequence, east, northeast, northweest, west, southwest, and southeast
let mktab 6 nil-> hexvertextlist in
let hexvqrsvectors -> globalvectorlist in
let hex.VQRScenter -> hexcenter in
let hexcenter.posq-> q in
let hexcenter.posr -> r in
let hexcenter.poss -> s in
let hex.Isize -> size in
let 0 -> counter in
(
while (counter< sizetab hexvertextlist) do
(
let globalvectorlist.counter-> this_vector in
let hexvertextlist -> this_hex_vertex in
let this_vector -> [this_vector_q this_vector_r this_vector_s] in
(
_fooS strcatn "we are at vector number: "::(itoa counter):: " vector q is :"::(itoa this_vector_q):: " vector r is: "::(itoa this_vector_r):: " and vector s is : "::(itoa this_vector_s)::"\n"::nil;
//make a vertex
let mkQRSCoordinate [50 0 0]-> thisvertex in //initialize a qrs coordinate object to fill up with correct values in the function below (I haven't added the vectors to the center yet)
(
//todo: calculations to add vector.counter to center and place result in hex.lqrspoints list of QRSCoordinate objects, each of which contains a tuple of [I I I]. hex.lqrspoints.0 will be the east point, hex.lqrspoints.1 will be the northeast point, hex.lqrspoints.2 will be the northwest point, hex.lqrspoints.3 will be the west point, hex.lqrspoints.4 will be the southwest point, and hex.lqrspoints.5 will be the southeast point. after we create the points, we will convert them to xy coordinates and put those xy coordinates in the hex object as well later on
//
_fooS strcatn "vertex number: ":: (itoa counter)::" has been created"::"\n"::nil;
//load created vertex into hex.lqrspoints table for the hex object that called this function
//something is not working here:
set hex.lqrspoints.counter = thisvertex ;
_fooS strcatn "this_created_vertex q is: " ::(itoa thisvertex.posq)::" this_created_vertex r is: " ::(itoa thisvertex.posr)::"\n:"::"and this_created_vertex s is: " ::(itoa thisvertex.poss)::nil;
0;
);
set counter = counter+1;
0;
);
0;
);
0;
);
//test to see if hex.lqrspoints has been filled, as per console, it remains empty. here i pick item 2 in the table which contains a total of 6 items
let hex.lqrspoints.2 -> firstpoint in
_fooS strcatn "the q coordinate of the qrs object at position zero of lqrspoints list is":: (itoa firstpoint.posq)::"\n"::nil;
//the console doesn't display any value for firstpoint.posq
0;;
fun inithex()=
//let mkTab 1 nil-> xytab in
let mkXYVertex [1 1] -> xyvert in
_fooS itoa xyvert.posx;
let mkXYVertex [1 1] -> xyvert in
let mktab 5 xyvert -> xytab in
//hexagon size is 10 in statement below with center at qrs 0 0 0
let mkQRSCoordinate [0 0 0] -> center in //create QRSCoordinate
//for center
let mkHexagon [center 10 xytab nil nil nil nil nil]-> hex in
let mkXYVertex [10 20] -> xyvert in
let mktab 1 xyvert -> xytab in
let xytab.0-> xvert in
(
createqrshexvectors hex;
create_vertex_qrscoordinates hex;
0;
);
0;;
fun main()=
_showconsole;
_fooS "showing console";
inithex;
0;;
thanks for your input!
-Dan
Last edited by hebdemnobad (30-Sep-2024 18:27:13)
Offline
somehow this thread duplicated: i solved problem delete if you want
Offline