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

Expanding and utilizing the engine via C++.
  • 1
  • 2
18 posts Page 1 of 2
aMoistKite
Posts: 18
Joined: Wed Mar 06, 2019 10:07 am
by aMoistKite » Tue Mar 12, 2019 2:41 pm
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"]);
rlranft
Posts: 306
Joined: Thu Feb 05, 2015 3:11 pm
 
by rlranft » Tue Mar 12, 2019 7:51 pm
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?
aMoistKite
Posts: 18
Joined: Wed Mar 06, 2019 10:07 am
by aMoistKite » Wed Mar 13, 2019 4:39 am
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.
aMoistKite
Posts: 18
Joined: Wed Mar 06, 2019 10:07 am
by aMoistKite » Sat Mar 16, 2019 6:53 am
So could anyone give me some examples?
Bloodknight
Posts: 226
Joined: Tue Feb 03, 2015 8:58 pm
by Bloodknight » Sat Mar 16, 2019 4:40 pm
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
aMoistKite
Posts: 18
Joined: Wed Mar 06, 2019 10:07 am
by aMoistKite » Sun Mar 17, 2019 6:50 am
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.
NeonTiger
Posts: 9
Joined: Sun Aug 02, 2015 4:50 am
by NeonTiger » Sun Mar 17, 2019 10:33 pm
What about array objects?
aMoistKite
Posts: 18
Joined: Wed Mar 06, 2019 10:07 am
by aMoistKite » Mon Mar 18, 2019 5:22 am
What about array objects?
May I have an example?
NeonTiger
Posts: 9
Joined: Sun Aug 02, 2015 4:50 am
by NeonTiger » Mon Mar 18, 2019 3:37 pm
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
aMoistKite
Posts: 18
Joined: Wed Mar 06, 2019 10:07 am
by aMoistKite » Wed Mar 20, 2019 3:46 pm
I was meaning an example how to define one in C++ and pass one it to torquescript.
  • 1
  • 2
18 posts Page 1 of 2

Who is online

Users browsing this forum: No registered users and 10 guests