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.

Newcomers DBPro Corner / Why does this code cause my game to crash?

Author
Message
Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 27th Jun 2009 22:23


The array insert at bottom is what is causing it. Whenever I try inserting something at the bottom, top, or at an element, the whole thing freezes up and crashes.
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 27th Jun 2009 22:42
have you tried dimming the array this way:

Dim Array(0) as String

Instead of this:

Dim Array$(0)

other than that i don't see the problem.

Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 27th Jun 2009 23:05
Why would that change anything?
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 27th Jun 2009 23:49
Your for-loop is running until array count(Array) is reached. DBPro evaluates the beginning and end statement for such loops in each iteration and thus you will get another run whenever you insert another element. That is probably not what causes your problem though, but it's worth thinking of.

Quote: "array delete element array$(),b
array insert at element array$(),b "

That is probably what causes problems. If b is the last element in the array and you remove it, then the index b is out of bounds when you later try to insert at that element.
By the way, why would you want to remove an element only to recreate it again? You can just overwrite the previous entries, you know

Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 28th Jun 2009 00:21 Edited at: 28th Jun 2009 00:51
Quote: "You can just overwrite the previous entries, you know"


You're right... IDK why I didn't think of that lol.

But that's not the problem. Here is the code I am now using:



The "}" symbol needs to stay at the bottom of the array at all times. But whenever I try adding a new element to the array inside the for loop, the whole thing freezes up and crashes. How else could I do this?

Basically, in the end, it will check if the string already exists in the array, if so it will change the string and add a "v2" after it. If the string isn't already there it adds it to the second to last spot in the array, the last spot being "}".

If I take the insert element out of the for loop and put it just after it, it works fine, but then it adds a new slot whether or not the string already existed in the array.

EDIT: I kind of figured how to do it. I need to set a variable so that if it doesn't find the string, then it sets it to one. If that variable is set to one then it inserts the string to the bottom.

Since it's a for loop, it will always end up being one, because only one of the passes through the for loop won't set it to 0. I guess I'll just have to inc the variable, and if it is less than the array index then it doesn't add it to the bottom.

Am I on the right track?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Jun 2009 07:05
My question is why add "Body {" and "}" to the array at all. If it's for just printing to the screen you can just print it before and after to give the illusion it's in the array. Same thing with saving to a file.



Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 28th Jun 2009 07:28
Because it will end up saving it to a CSS file. I figured it out though with the concept I posted above. Everything is working smoothly.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Jun 2009 08:00
You mean like this?



I'm glad it's working good.

Clbembry
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Minnesota
Posted: 28th Jun 2009 08:47
Oh... Umm... You see... I like to do things the necessarily hard way...
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Jun 2009 19:08
Oh ok.

Login to post a reply

Server time is: 2024-09-28 08:33:06
Your offset time is: 2024-09-28 08:33:06