How to access the device ID in script?
by Conor O'Kane · in iTorque 2D · 01/24/2009 (5:55 am) · 7 replies
Is there a way to access the device's ID in script? I want to do an online scoreboard where the score is tied to the device ID.
About the author
www.cokane.com
#2
02/03/2009 (9:08 am)
Something like that did roughly work Mat, thanks!
#3
Mat, we should keep track on all these great additions. (quit, gotoHtml, getDeviceID, etc...)
It's being tested and working great for us.
Would it to be rolled into the next version?
02/03/2009 (11:07 am)
This is just keep getting better.Mat, we should keep track on all these great additions. (quit, gotoHtml, getDeviceID, etc...)
It's being tested and working great for us.
Would it to be rolled into the next version?
#4
My syntax was closer to this, in S32 main(S32 argc, char *argv[]) in iPhoneMain.mm
I then made a couple of methods to access those via script:
I also had to add the extra variables to the platState class of course (and initialize them).
02/03/2009 (12:04 pm)
Mine was a bit more roundabout, I decided to extend the platState class to hold the extra info as it only gets populated on startup ideally.My syntax was closer to this, in S32 main(S32 argc, char *argv[]) in iPhoneMain.mm
//Get the device unique ID NSString *nsStrUniqueID = [UIDevice currentDevice ].uniqueIdentifier; const char *strUniqueID = [nsStrUniqueID UTF8String ]; platState.uniqueID = strUniqueID; //Get the device unique ID NSString *nsStrModel = [UIDevice currentDevice ].model; const char *strModel = [nsStrModel UTF8String ]; platState.model = strModel;
I then made a couple of methods to access those via script:
ConsoleFunction(getDeviceModel, const char*, 1, 1, "")
{
char* ret = Con::getReturnBuffer( 1024 );
dSprintf(ret, 1024, platState.model);
return ret;
}
ConsoleFunction(getDeviceID, const char*, 1, 1, "")
{
char* ret = Con::getReturnBuffer( 1024 );
dSprintf(ret, 1024, platState.uniqueID);
return ret;
}I also had to add the extra variables to the platState class of course (and initialize them).
#5
02/07/2009 (7:35 pm)
Thanks guys. I've managed to get Dave's example working in my game, so I can use the device ID for score submissions.
#6
I've tried putting them in game/main.cc but tgb doesn't seem to find the functions once I call them.
05/12/2009 (2:46 am)
so where do you put the consolefunctions?I've tried putting them in game/main.cc but tgb doesn't seem to find the functions once I call them.
#7
I'm at work, so I'll test it when I get home. If anyone can confirm that this is the right spot to put those lines in, I'll appreciate it.
UPDATE: I'm getting build errors, specifically related to the platState. Is this predefined elsewhere, or do you need to include another module?
UPDATE 2: Can you explain to the non Objective-C-savvy?
06/24/2009 (8:14 am)
I just found this thread and thought it could be useful.. as for where to put the ConsoleFunctions, I'm making a guess that it'll be in /engine/source/console/consolefunctions.ccI'm at work, so I'll test it when I get home. If anyone can confirm that this is the right spot to put those lines in, I'll appreciate it.
UPDATE: I'm getting build errors, specifically related to the platState. Is this predefined elsewhere, or do you need to include another module?
UPDATE 2: Can you explain to the non Objective-C-savvy?
Quote:I also had to add the extra variables to the platState class of course (and initialize them).
Torque 3D Owner Mat Valadez
Default Studio Name
put that in a ConsoleFunction() and you're set
Something like this (this is totally untested)
ConsoleFunction( getDeviceID, const char*, 1, 1 "gets a device unique string" ) { NSString *deviceID = [[UIDevice currentDevice] uniqueIdentifier]; //or maybe [NSString alloc] initWithData: [[UIDevice currentDevice] uniqueIdentifier];//dunno, Objective C is not my forté const char *string = Con::getReturnBuffer(1024);//no idea how big this will need to be //I think NSStrings must be converted to c strings? dStrcpy( string, [deviceId UTF8String] ); return string; }I forget exaclty how the NSstring->C string stuff works, but that should get you started.