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 / Help with arrays

Author
Message
Spaweb
20
Years of Service
User Offline
Joined: 3rd Mar 2004
Location: Somewhere on the Astral Plane
Posted: 3rd Mar 2004 20:08
Anyone got any idea why this won't work?


This is from my main text adventure game loop. type is my subroutine for printing text onscreen. items is the array I'm using to record an item's location: one for each room, with an additional one for the player's inventory(variable player). 1 for item there, 0 for item not there. When the game prints an "AN ITEM IS HERE" message onscreen, it gives me an error message saying, "Array accessed out of bounds", and points me to the items array. What does this mean?
xtom
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 3rd Mar 2004 20:33
From what you say it sounds like itemname$(t) is giving the error. So t is probably reaching a higher number than the number you dimed the array at.

Keep in mind when using arrays that the first location is 0 then 1,2,3,etc

eg. for t=0 to itemstotal-1

It's possible to code ignoring that first 0 location but you'd have to dim your arrays by 1 higher and this isn't really good practise.
Spaweb
20
Years of Service
User Offline
Joined: 3rd Mar 2004
Location: Somewhere on the Astral Plane
Posted: 9th Mar 2004 15:19
Quote: "Keep in mind when using arrays that the first location is 0 then 1,2,3,etc"

Damn I'd forgotten that...
OK I'll try it out
Spaweb
20
Years of Service
User Offline
Joined: 3rd Mar 2004
Location: Somewhere on the Astral Plane
Posted: 16th Mar 2004 19:53
Aaaahhh... that's better. Thanks, xtom.

Login to post a reply

Server time is: 2024-09-22 02:55:36
Your offset time is: 2024-09-22 02:55:36