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.

DarkBASIC Professional Discussion / New String using Dynamic Arrays

Author
Message
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 30th Jan 2011 21:13
Hello,

i want to create a lot of random Names and save the result in another Array. Name and Surname are Saved in separate Text-Files.

Here is my Code



But i get the Runtime Error #118, "Array does not exist, or array subscribt out of Bounds". For the line marked above.

I hope, someone can help.

Thanks
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jan 2011 21:56
Say your files have 10 items in, so maxcount is set to 10. Then you read the data into your arrays, inserting 10 items, from 0 to 9. Then you are choosing random numbers from 0 to 10 ... see the problem yet?

DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 31st Jan 2011 08:41
Hello IanM,

i understand what you want to tell me (or better, i think that i do that)

You want to say, that i exceed the area of the array, is that correct?

But i am not clever enough to find where i did that.

Will the Code work if i subtract 1 from MaxCount and MaxCount2 (I am on work so i cant test it yet)?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jan 2011 14:01
Basically, yes. Just change your random number selections to this:


DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 31st Jan 2011 14:22
Thanks for your fast help.

I will try it out at Home tonight.

Hope that this will do it.

Till then.
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 31st Jan 2011 18:58
So. I changed MaxCount, but it is still the same Problem.

I think i should try it with a smaller Array, and look what will happen. So i write some new lines and look what will happen. I will post the result as soon as possible.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jan 2011 19:23
Actually, there were also problems there with your file reading too.

I've rewritten your loading code and added comments:


enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 31st Jan 2011 19:33 Edited at: 31st Jan 2011 19:35
Correct me if I'm wrong, but I think array count() would return the value 10 if there are 10 items in the array.
So you would still need to use RND(MaxCount - 1) because items start at 0, so the range would be 0-9 = 10 items.



IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jan 2011 20:07
Ok, consider yourself corrected

Although the function is called ARRAY COUNT, it doesn't actually tell you the number of items in the array at all - it tells you the highest valid array index.

So when you DIM A(10), you have 11 items from 0 to 10, and ARRAY COUNT() returns 10.

kamac
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 31st Jan 2011 20:22
Maybe this is unneccesary, but change this
Center Text 320, 240, "An Error has Occured. File not Found. Press any Key to End!"

into this

Exit Prompt "An Error has Occured. File not Found. Press any Key to End!","ERROR"
end


To make it look more professional

In progress of making Archery Simulator... Or maybe not simulator x]?

@There'll be a sig @
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 31st Jan 2011 20:27 Edited at: 31st Jan 2011 20:36
Thanks to all of your answers.

In the Meantime i changed the Code. It works fine now.



Thanks again.

P.S.
I did not see, that IanM has already corrected the former Code. So special thanks to IanM for the effort he took to correct my Code. Thanks to all of You Guys.
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 1st Feb 2011 19:26
So, i have a Question again, concerning the Dynamic arrays.

I put the Dynamic array in a Function



The Function is called out from the Function MouseControl. A function controlled by the main Loop



If i do so, then i get the error No. 118 again. If i Call the InitNewGame()-Function before the Main-Loop and not with the MouseControl()-Function then i get the results i was looking for. The Array ist Global like before.

Long Speech short Question:

Why is it not possible (for me) to create the Dynamic Array out from the MouseControl-Function
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Feb 2011 21:43
Short answer: don't know - post complete runnable code

DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 2nd Feb 2011 09:48 Edited at: 2nd Feb 2011 19:53


The reason i did not post the whole code is, that the Code was written in German and i have to rewrite the Code in a understandable language. I hope i did not overlook something.
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 2nd Feb 2011 21:29
Help Anyone?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Feb 2011 22:26
I hadn't forgotten you

What happening is that your code is too fast! Well, not really.

What is happening, is that because you haven't protected yourself from it, your InitNewGame function is being called multiple times.

First time through, it runs just fine and does what you tell it. At the end of the function, you then destroy the Name and Surname arrays.

The second time though, you attempt to load into the Name array, but you've already destroyed that array... crash!

Just add a flag to your code to stop your function being called multiple times, or use EMPTY ARRAY instead of UNDIM.

Also, you need to do to TeamArray whatever you do to Name and Surname too (either UNDIM or EMPTY ARRAY).

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 2nd Feb 2011 22:39
Heya DBPro User.

Recently, I actually coded something very similar to what you're trying to do. I posted my thoughts and workings up in the DBPro New Comers forum,

http://forum.thegamecreators.com/?m=forum_view&t=178859&b=7

Check it out, as I use some pretty interesting techniques in the final code, such as array pointers.

Help build an online DarkBASIC Professional help archive.

http://dbprohelp.wikia.com/wiki/DarkBASIC_Professional_Help_Wiki
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 2nd Feb 2011 23:23
Thank you guys. why i did not perceived that

@Burning Feet Man
I will do so. Im looking forward to it

Login to post a reply

Server time is: 2026-07-17 18:54:45
Your offset time is: 2026-07-17 18:54:45