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.

Author
Message
Levanthus
23
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 9th Aug 2014 02:49
Now i've never been good with arrays and i have just spent hours trawling through the forums to find and answer to my problem but to no avail... so here we go...

i have my inventory array set up quite simply as:-


and at current i have two items to put into said Inventory, a key and some paper, now if i pick up the key first and then the paper and then use the paper (thus deleting it from the array) everything works fine, but if i pick up the paper and then the key and use the paper i get the runtime error 118 array doesn't exist or subscript out of bounds, now i found loads of threads about this error but nothing seems to solve my issue... and it's in this nest of code where it says the error lies :-

fro what i can gather it's because It calls for the Array count but then having to delete an object from it the array count is then wrong so it spazzes out yes? Arrays have always been a cause for headaches for me so any help here would be great.

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 7 GB Ram, Radeon HD 4650, 3.6 TB HDD
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Aug 2014 03:15
At first glance it looks ok. The for-loop calls array count() every iteration, so it should update correctly.

What if you do something like this?



If you only have one instance of "Paper" stored in the array, there's no real reason to continue looping. Breaking out early would also solve any out of bounds errors:



Levanthus
23
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 9th Aug 2014 04:08
So bloody simple... thank you... i feel like a right idiot now hahaha

I can see from your smile, you're not here for the sunset

Windows 7 64 bit, AMD Phenom II x4 Black edition, 7 GB Ram, Radeon HD 4650, 3.6 TB HDD

Login to post a reply

Server time is: 2026-07-06 04:30:24
Your offset time is: 2026-07-06 04:30:24