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 / Array out of bounds? I don't see it.

Author
Message
Ace of Springs
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: Cambodia
Posted: 3rd Jun 2012 09:03


Have also tried


zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 3rd Jun 2012 09:09 Edited at: 3rd Jun 2012 09:12
That shouldn't be causing you an issue. Where in your code are you dimming your array?

This would work too:
since Dim iinventory(30) would go from iinventory(0) to iinventory(30)

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Ace of Springs
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: Cambodia
Posted: 3rd Jun 2012 09:11 Edited at: 3rd Jun 2012 09:14
I dim the array at the top of the code outside of all functions and loops, but am trying to access array within a function.


Here is entire function if it helps:


zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 3rd Jun 2012 09:17
Hmm... Does this snippet work for you?:


Is it possible that the array names are different in your source? Are you undimming it anywhere?

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Ace of Springs
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: Cambodia
Posted: 3rd Jun 2012 09:25
that snippet does work. double checked names are the same and no undimming anywhere. Even re-wrote the code again just in case i missed something and still get same error. Runtime 118 - Array does not exist or subscript is out of bounds. It just doesn't make any sense.

Ace of Springs
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: Cambodia
Posted: 3rd Jun 2012 09:30
Okay, it is definately some sort of global issue. I just tried to dim the array inside the function and it works fine. Then I tried to dim it immediately before the function and it does not work. Any idea why this may be?

zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 3rd Jun 2012 09:48 Edited at: 3rd Jun 2012 09:48
I'm not sure. It shouldn't work right before the function since that line would not ever be processed. Maybe try putting the dim just before the main loop's initialization? Are you using multiple source files, perhaps?

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Ace of Springs
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: Cambodia
Posted: 3rd Jun 2012 09:53 Edited at: 3rd Jun 2012 09:58
Quote: "would not ever be processed"


that got me thinking. It was most definately in a spot that you would think would not process. Didn't really think about it because I have all this other stuff there:

that process just fine. But moved the dim code to right before the main loop in that level function and it seems to work fine now. It is also an acceptable location for me so I can continue on. Not sure why it works with globals and declaring types but not arrays. Anyway, problem solved. I much appreciate the help sir. Also am using multiple source files and alot of jumping around in the code so it gets confusing sometimes

zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 3rd Jun 2012 10:09
You could always put a VariableInitFunction() in each included source file that gets called before the game starts. That might help, and could be a little more oraganized as well.

#include inventory
#include stats
#include enemyAI

inventoryInit()
statsInit()
enemyInit()

do
do stuff
loop

end

function inventoryInit()
global this
global that
dim this()
dim that()
endfunction

etc.

Anyway, glad it's working!

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Jun 2012 17:44
The code has to actually run through the "dim" command before you try to access the array, or the array will be uninitialised.

[b]
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 3rd Jun 2012 22:41
+1 to what Diggsey said. Arrays in dbp aren't magic things picked up by the compiler and initialised before the code runs. Think of them as just normal lines of code that need to be run through for them to come into existence.

This would not work:



... as Bob would never be reached so never initialised. Bob needs to be defined before the loop begins.

It'd be more helpful if DBP reported the array as not existing, but it doesn't!

Ace of Springs
14
Years of Service
User Offline
Joined: 10th Jan 2012
Location: Cambodia
Posted: 3rd Jun 2012 23:23
Yea, I understand how they work now. I just assumed they would be picked up in the same way standard global variables are. Learn something new everyday

Login to post a reply

Server time is: 2026-07-07 22:23:37
Your offset time is: 2026-07-07 22:23:37