Page 1 of 2

Define a 2D array in C++ and passing to TS

Posted: Tue Mar 12, 2019 2:41 pm
by aMoistKite
How would i go about creating a 2D array in C++ and passing off to torquescript so that it would return like so:

Code: Select all

%data = funcThatMakeArrays(); echo(%data[1, "index2"]);

Re: Define a 2D array in C++ and passing to TS

Posted: Tue Mar 12, 2019 7:51 pm
by rlranft
Do you need it to do exactly that? Because it'd be pretty simple to create a SimGroup in your engine function, populate it, and return that. SimGroups can be indexed and iterated over in TS.

Easier still would be to just make a quick "SimGroup manager" class script-side.

What's the exact use-case?

Re: Define a 2D array in C++ and passing to TS

Posted: Wed Mar 13, 2019 4:39 am
by aMoistKite
I guess it does not need to do exactly that. I am simply pulling data from a database but since i need to access the database very often I wanted as much of the work done in C++ as possible for performance.

Re: Define a 2D array in C++ and passing to TS

Posted: Sat Mar 16, 2019 6:53 am
by aMoistKite
So could anyone give me some examples?

Re: Define a 2D array in C++ and passing to TS

Posted: Sat Mar 16, 2019 4:40 pm
by Bloodknight
sqlite is integrated into the engine with a cmake option, if nothing else this should operate as a framework for adding any other database system

Re: Define a 2D array in C++ and passing to TS

Posted: Sun Mar 17, 2019 6:50 am
by aMoistKite
I do not see any cmake option for sqlite, and all the resources i could find on it over on garagegames have dead links. SQLite would not work for my application anyway.

Re: Define a 2D array in C++ and passing to TS

Posted: Sun Mar 17, 2019 10:33 pm
by NeonTiger
What about array objects?

Re: Define a 2D array in C++ and passing to TS

Posted: Mon Mar 18, 2019 5:22 am
by aMoistKite
What about array objects?
May I have an example?

Re: Define a 2D array in C++ and passing to TS

Posted: Mon Mar 18, 2019 3:37 pm
by NeonTiger
http://docs.garagegames.com/torque-3d/r ... bject.html

new ArrayObject(numArray);

numArray.add(1,4);
numArray.add(2,3);
numArray.add(3,8);

numArray.add("1,1",5); 
numArray.add("1,2",9); 

function ArrayObject::getKeyFromValue(%this,%value){
   return %this.getKey(%this.getIndexFromValue(%value));
}
function ArrayObject::getValueFromKey(%this,%key){
   return %this.getValue(%this.getIndexFromKey(%key));
}

numArray.getValueFromKey(1); // will return 4
numArray.getValueFromKey("1,1"); // will return 5

Re: Define a 2D array in C++ and passing to TS

Posted: Wed Mar 20, 2019 3:46 pm
by aMoistKite
I was meaning an example how to define one in C++ and pass one it to torquescript.