Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Bug in AGK 108.24 [Tier 1]

Author
Message
Abiz
12
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 3rd Sep 2014 03:10
After hours of research, I can only classify this as a bug:

Here is my code:
qty = Val( getstringtoken( response$, "|^", 1 ) )
Print( str(qty) ) // prints 15
if qty > 0 then print("It really is an integer")
// qty = 15
FOR T=2 TO qty STEP 2
PrintC( GetStringToken( response$, "|^", T ) )
PrintC( "=" )
Print( GetStringToken( response$, "|^", T + 1 ) )
NEXT T


The above code DOES NOT work. There is just simply no output.
If I remove the // in front of qty = 15, then it DOES work.
qty truly is an integer as you can see from the code above that.
Nevertheless the compiler (for some mysterious reason) cannot properly evaluate qty in the code as it is written.

Even weirder is this one:
qty = Val( getstringtoken( response$, "|^", 1 ) )
tmp = 1
repeat
inc tmp
PrintC( getstringtoken( response$, "|^", tmp ) )
PrintC( "=" )
inc tmp
Print( getstringtoken( response$, "|^", tmp ) )
until tmp = qty

Which is a simple rewrite of the FOR NEXT loop.
This crashes the entire program (Again no compiler errors or warnings)

It is simply frustrating to continuously have to fight these kind of problems and re-write and re-write the code until one can finally find where the problem is.

Can I make the compiler (or the code) report on data mismatches, or make it more sensitive? These type of errors are just costing me too much (valuable) coding time.

Thanks,
James
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 3rd Sep 2014 11:24 Edited at: 3rd Sep 2014 11:26
What is in response$?

In the second example, if tmp is never = to qty you have an infinite loop. And what if you are past the end of response$? Does this crash or just return an empty string?

What happens if Val() is passed an illegal parameter?

Converting strings to numbers is inherently a dangerous operation. AppGameKit T1 could do with an exception catching mechanism. In Pascal (including AppGameKit Pascal) a conversion error will throw an eConvertError exception. By catching this we can do something sensible. This is VERY important if the user is inputting numeric values:

Function SafeConvertInt(const s : string; defvalue : integer):integer;
begin
try
result := IntToStr(s);
except
result := defvalue;
end
end;

That will never cause a problem - and we can test for an illegal entry by making defvalue some error code we define, or have it return a sensible default.

-- Jim - When is there going to be a release?
Abiz
12
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 3rd Sep 2014 17:59
I agree the conversion is always an issue, since there are no catch clauses in tier 1, or data types.

However, in this particular case it really is unimportant what is in the response$ since CountStringTokens will always return an integer (which could essentially be 1, if no delimiters were found), according to the documentation.

And while I'm writing this I see my error. And thus this is not a bug (perhaps), but my fault, since I didn't use that value for my loop. I will test that first and report back.

James
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 4th Sep 2014 03:07 Edited at: 4th Sep 2014 03:09
to dig further into the problem....can you provide the main string that it is grabbing these values from. im concerned for the use of this symbol ^ which is a math function [to the power of] which may not be a good string delimiter.

Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 4th Sep 2014 09:32
I'm not seeing the problem here

I just ran:
response$ = "6|^16|^17|^18|^19|^20|^21"



And got:
6
It really is an integer
16=17
18=19
20=21

It appears as if the string is being parsed properly.
What is in your response$ ?
What is your output?

You do realize that you need to put a sync call in to write to the screen?
Also, I'd highly advise against using 2 characters as separators. I've often used chr(31) so that it won't be mistaken for anything else.

Abiz
12
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 9th Sep 2014 00:06
Sorry to be late in reporting back. But I used the wrong variable and hence it didn't execute.
When I fixed the variable, all was fine.
Thanks for all help and suggestions.

Login to post a reply

Server time is: 2024-11-25 09:22:17
Your offset time is: 2024-11-25 09:22:17