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 / Shold this work or generate an error?

Author
Message
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 7th May 2012 07:40


In 1065 this just crashed. Now in 1071 this gives an error. If you remove the REM it will assign a value to the string, although empty, and you can write it to the file. Can't this be handled differently by AppGameKit?

bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 8th May 2012 14:40
Sounds like a bug.

As a temporary fix, I haven't tested it, by try something like:

Left(string, Len(string))

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th May 2012 16:40
Personally I prefer to get an error to a crash, at least then I can work out what happened. What exactly is the behaviour you are asking for?

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th May 2012 18:29
I suspect your original crash may because when you create the array, you don't define a value for the string. And, since it is in a UDT, the definition of the array may not set default values for the string.

Do you get the same failure if you try this:


Cheers,
Ancient Lady
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 8th May 2012 19:56 Edited at: 8th May 2012 19:56
but "" should be a valid value that he did assign to the variable.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 8th May 2012 20:39 Edited at: 8th May 2012 20:40
Guess I should have explain the problem better. You cannot write an empty string from a type to a file without setting it to "" first. This is no problem with integers. So whenever I add something to my list (array) I have to set all strings to "" because they will contain no data when added.

In 1065 this just crashed the program. I was thinking that either it got fixed in 107 or I should report it as a bug. But now this generates an error message instead. So, the question is: Should AppGameKit handle these empty strings in arrays when writing to files, or should it generate errors? To me it seems weird that it doesn't work.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th May 2012 20:47 Edited at: 8th May 2012 20:48
In Digital Awakening's original post, he said that it worked when he uncommented the line that set the string to "".

When the line that sets the string is commented out, he gets the failure. In that case his test array has one testType object.

I don't know how the compiler handles initializing the values in arrays made from UDTs.

When I run Digital Awakenings original code, with the commented line, the error message is:
Quote: "Failed to write string, the string has not been assigned a value at line <x>"


Uncommenting the line makes it work.

And I was wrong about trying it with a simple variable declared as a string, but without assigning a value. You get the same error.

Unlike numbers, where a default of zero works because the memory allocated for the variable will be set to zero, a string is more complex.

Strings in basic are dynamic creatures. The memory allocated will start with the number of characters in the string, followed by the characters themselves. And probably a null character to definitively end the string, but not necessarily.

But you have to set a string value before it knows how much memory it needs to allocate. Effectively, an undefined string is a pointer with a null value.

Cheers,
Ancient Lady
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 8th May 2012 22:14
I found this problem annoying at first with AppGameKit, it has always done this. I did exactly the same to fix it by assigning each string with an empty string (""). I have since got into the habit of only saving a file after I have assigned a value to it. There is really no point in doing so anyway, if there is nothing to save. Also, if I know what the text is going to be used for I assign it some text to begin with to avoid the problem altogether.

It can make for a little setup work before your game runs but works well in general. You can then edit the strings whenever they need updating.

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 8th May 2012 23:55
DVader:
I'm making a world map editor for my game and it is a little more complex than that. I store all objects in an UDT array and when they are created none of the strings contain any data, and many never will. It's much easier for me to simply loop through the array writing everything to the file and then loop again when I load. It might not be efficient or flexible but it sure is easy to code.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 9th May 2012 08:39 Edited at: 9th May 2012 08:40
Error or crash, neither produce a working app.
Quote: "I store all objects in an UDT array"

It's considered good practice to initialise UDT's contents when created.
Quote: "and when they are created none of the strings contain any data, and many never will."

It's considered good practice to initialise string contents when created

As Ancient Lady explained, neither are assigned default values on creation, so are undefined.

Undefined variables lead to unpredictable results.
Quote: "It's much easier for me to simply loop through the array writing everything to the file"

SO surely, it would be simple to loop through the array and initialise the contents?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th May 2012 10:53
Would it not also be fairly simple for AppGameKit to automatically assign an empty string value when a string is defined or an array is dimensioned or re-dimensioned?

I would suggest this in the google bug board. I know that there was an issue with running "val()" on an undefined string which they have (I think) already fixed.

bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 9th May 2012 11:46
ah, I misunderstood the original post. Carry on.

Login to post a reply

Server time is: 2024-11-23 11:19:50
Your offset time is: 2024-11-23 11:19:50