Unitsync units
Moderator: Moderators
Unitsync units
Unitsync has a setup for getting unitnames from a mod. However how this si to be used is unclear.
So far I do the following setup:
1)Initialize unitsync
2)Set the primary ModArchive and Load all its archives
3)Call ProcessUnits taking the return value as the number of units
4)Enter a loop retrieving each unitsname
The problem is as soon as I try to retrieve a unitsname in the loop unitsync crashes and java outputs a cryptic error log and exits citing unitsync as the issue.
The only example of howto do this is buried in tasclient somewhere, and tasclient code is nasty enough to read without the syntax style changing and beign messy.
So far I do the following setup:
1)Initialize unitsync
2)Set the primary ModArchive and Load all its archives
3)Call ProcessUnits taking the return value as the number of units
4)Enter a loop retrieving each unitsname
The problem is as soon as I try to retrieve a unitsname in the loop unitsync crashes and java outputs a cryptic error log and exits citing unitsync as the issue.
The only example of howto do this is buried in tasclient somewhere, and tasclient code is nasty enough to read without the syntax style changing and beign messy.
- Michilus_nimbus
- Posts: 634
- Joined: 19 Nov 2004, 20:38
so
Like that?
Code: Select all
int n = GteUnitCount();
for(int i = 0; i < n){
int x = ProcessUnits();
AddUnit(GetUnitName(x));
}
hmm that makes even elss sense now:
unitcount = CUnitSyncJNIBindings.ProcessUnits ();
unitcount now contains the fulll n# of units in that mod from the first call. If I was correct in my previous post it would be 1 and it would increment.
Sometimes I wonder why unitsync was written in such an archaic way without even a single comment to explain each function unless the functions usage is painfully obvious.
unitcount = CUnitSyncJNIBindings.ProcessUnits ();
unitcount now contains the fulll n# of units in that mod from the first call. If I was correct in my previous post it would be 1 and it would increment.
Sometimes I wonder why unitsync was written in such an archaic way without even a single comment to explain each function unless the functions usage is painfully obvious.
Code: Select all
int i = CUnitSyncJNIBindings.GetUnitCount();
System.out.println(i);
console wrote:1
- Michilus_nimbus
- Posts: 634
- Joined: 19 Nov 2004, 20:38
Ah, I remember now.
ProcessUnits returns the number of units that haven't been processed yet, and GetUnitCount returns the opposite.
so:
Would put every unit name in a list in Python
ProcessUnits returns the number of units that haven't been processed yet, and GetUnitCount returns the opposite.
so:
Code: Select all
while unitsync.ProcessUnits():
pass
l = []
for i in range(0,unitsync.GetUnitCount()):
l.append(unitsync.GetUnitName(i))
Last edited by Michilus_nimbus on 11 Jul 2007, 19:34, edited 1 time in total.
Basically correct yes. Here's some pseudocode to retrieve a mod's internal/external unit-names:
Edit: beaten to the punch I see 
Code: Select all
AddAllArchives("XTAPE.sd7");
while (ProcessUnits() > 0);
int n = GetUnitCount();
for (int i = 0; i < n; i++) {
cout << "unit: " << i << endl;
cout << "int. name: " << GetUnitName(i) << endl; // eg. "armbbq"
cout << "ext. name: " << GetFullUnitName(i) << endl; // eg. "Arm Barbebeque Rack"
}

blah, while you wrote those replies I figured it out anyway:
Now we just need a wiki page with all of this.
Code: Select all
units.clear ();
while(CUnitSyncJNIBindings.ProcessUnits ()>0){}
unitcount = CUnitSyncJNIBindings.GetUnitCount ();
for(int i = 0; i < unitcount; i++){
String s = CUnitSyncJNIBindings.GetUnitName (i);
System.out.println(s);
units.add (s);
}
http://www.stack.nl/~dimitri/doxygen/do ... #latestman
Or look at other functions that are already commented (thats by far the easiest
):
https://spring.clan-sy.com/svn/spring/t ... System.cpp
No need to bother with the initial *'s btw.
Or look at other functions that are already commented (thats by far the easiest

https://spring.clan-sy.com/svn/spring/t ... System.cpp
No need to bother with the initial *'s btw.
I hope mono supports p/invoke...!?
I will make a search on this.
Edit: Yeah should work: http://www.mono-project.com/Interop_wit ... _Libraries
I will make a search on this.
Edit: Yeah should work: http://www.mono-project.com/Interop_wit ... _Libraries