Problem with my if?
by Skylar Kelty · in Torque Game Engine · 09/24/2006 (1:47 am) · 6 replies
Hi,
Im trying to get my game topop up a message if the current version is greater than the game version.
Heres the code:
Heres the problem:
$latestversion = 1.0
$gameversion = 0.9
but no message comes up, the echo's show the right versions and $latestversion is greater than $gameversion
why no message?
if I change the if() to:
if($latestversion != $gameversion)
then a message always comes up, even if the two versions are the same, why?
Thanks in advance
EDIT:
If I do this:
echo($latestversion + $gameversion);
I get the value of $gameversion, any ideas?
Im trying to get my game topop up a message if the current version is greater than the game version.
Heres the code:
function MainMenuGui::onWake(%this)
{
new TCPObject(updtlst){};
updtlst.connect("sphyxgames.com:80/dawnofmenupdate/latestversion.xml");
}
function updtlst::onConnected( %this )
{
// Reset some useful state information.
$updt::lineCount = 0;
$updt::requestResults = "";
// Request our RSS.
%this.send("GET " @ "/dawnofmenupdate/latestversion.xml" @ " HTTP/1.0\nHost: " @ "www.sphyxgames.com" @ "\nUser-Agent: " @ "Torque/1.4.2" @ "\n\r\n\r\n");
}
function updtlst::onLine(%this, %line)
{
%latestversion = %line;
$latestversion = %latestversion;
}
function updtlst::onDisconnect(%this)
{
checkversion();
}
function checkversion()
{
%file = new FileObject();
%file.openforRead("DawnOfMen/version.txt");
while( !%file.isEOF() )
{
%line = %file.readline();
$gameversion = %line;
}
%file.close();
%file.delete();
echo($latestversion);
echo($gameversion);
if($latestversion > $gameversion)
MessageBoxOK( "Update Avaliable!", "There is an update avaliable for download" );
}Heres the problem:
$latestversion = 1.0
$gameversion = 0.9
but no message comes up, the echo's show the right versions and $latestversion is greater than $gameversion
why no message?
if I change the if() to:
if($latestversion != $gameversion)
then a message always comes up, even if the two versions are the same, why?
Thanks in advance
EDIT:
If I do this:
echo($latestversion + $gameversion);
I get the value of $gameversion, any ideas?
About the author
#2
1.0
1.0
no message, good
If I change the value on the website
1.1
1.0
no message, bad
Edit: Yeah I did soemthing like what you did there and it worked too, but as soon as I get the value from the internet, it wont work
09/24/2006 (5:48 am)
Yeah, the echo's return this:1.0
1.0
no message, good
If I change the value on the website
1.1
1.0
no message, bad
Edit: Yeah I did soemthing like what you did there and it worked too, but as soon as I get the value from the internet, it wont work
#3
Edit: you're all welcome to use the script
10/15/2006 (1:05 pm)
I've fixed this:function checkversion(%currentversion)
{
%version = 1.0;
if(%currentversion > %version)
{
MessageBoxOK("Old Version", "Your version of - is not the most current version, please download the latest patch from -");
$OutOfDate = true;
}
}
function getlatestversion()
{
if($pref::cangetversions $= "1"){
new TCPObject(VersionObject);
VersionObject.connect("www.you.com:80");
}
}
function VersionObject::onConnected(%this)
{
$Version::lineCount = 0;
$Version::requestResults = "";
// Request our RSS.
%this.send("GET " @ "/latest.xml" @ " HTTP/1.0\nHost: " @ "www.you.com" @ "\nUser-Agent: " @ "TGE 1.4.2" @ "\n\r\n\r\n");
}
function VersionObject::onLine(%this, %line)
{
$Version::lineCount++;
$Version::requestResults = $Version::requestResults @ %line;
}
function VersionObject::onDisconnect(%this)
{
%version = getxmldata($Version::requestResults, "version", 0);
checkversion(%version);
}
function getxmldata(%string, %tag, %startChar)
{
%startTag = "<" @ %tag @ ">";
%endTag = "</" @ %tag @ ">";
%startTagOffset = strpos(%string, %startTag, %startChar);
%startOffset = %startTagOffset + strlen(%startTag);
%endTagOffset = strpos(%string, %endTag, %startOffset - 1);
if(%endTagOffset < 0)
return "";
%this.lastOffset = %endTagOffset;
%result = getSubStr(%string, %startOffset, %endTagOffset - %startOffset);
%result = strreplace(%result, """, "\"");
%result = strreplace(%result, "&", "&");
return %result;
}Edit: you're all welcome to use the script
#5
10/15/2006 (3:49 pm)
Note that you're assigning %latestversion but testing $latestversion. That's probably not what you want to be doing. (note dollar vs percent)
#6
10/16/2006 (8:04 am)
Where?
Torque Owner Tim Heldna
To test, I simply created a script to mimick what you're trying to achieve:
function testVersion() { $latestversion = 1.0; $gameversion = 0.9; echo($latestversion); echo($gameversion); if($latestversion > $gameversion) MessageBoxOK( "Update Avaliable!", "There is an update avaliable for download" ); }It worked fine.
Are you sure you're obtaining the right values for those two variables? If you are, you're just retrieving the number value right and not the whole string? I.e. Your console ehco's "1.0" and not "$latestversion = 1.0;"