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 Discussion / Please help me and my disfunctional arrays

Author
Message
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 3rd Jul 2004 03:21
I can usually figure out my own problems now, but I am desperate here. I was just finishing up the new Firewall demo and I ran into a very hard wall. This is painful.

The robots have a certain amount of power that they can use, and it recharges. This all used to work perfectly. Then yesterday I was going to finish it up and suddenly all my robots lost all power and they can't get any more There are two variables that I am using. One is rpowerhold#() and the other is rpower#() . rpowerhold#() holds the data for the amount of maximum power that a robot can hold. When a robot is build, this is in the code that fills its power:


(own is the owner of the robot and l is just the variable for a 'for next' loop, that is an l, not a 1. rdesign is predefined as the design of the robot. All designs have different amounts of power they can hold)

This used to work just fine. However, now, the rpower#() variable cannot hold any number! No matter what I put in it, it always goes right back to zero. Man, it is really annoying. Anyone else ever have this problem? I was considering it was possibly a memory shortage problem, but the rpower#() array is not defined last or anything, there are other arrays after it that work just fine. Here is a small snippet of my code, and the screen shot that I took from it that proves my point:


This prints the values to the screen, here is the screenshot:


As soon as I get this fixed I can release the Firewall 3.01 demo...

Xander Moser of Bolt Software
Firewall: Your Computer's First Defense - Real Time Strategy game
[href][/href]
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 3rd Jul 2004 04:26
what are the values of own, l and rdesign???, sounds like you are indexing an empty array location, did you make any changes to any of the code that could impact this? (you mentioned you where finishing up), try printing those values I mentioned, you may find one has defaulted to 0 for some reason, try forcing them to some specific value, if that works then you know it`s the code to blame, otherwise, congratulations, you just found a new compiler bug , you could also try deleting the .dbpro file and remaking it, sometimes that cures weird faults.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster.
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 3rd Jul 2004 05:26
This is DB Classic...

I printed to the screen both rpower#() and rpowerhold#(). rpowerhold#(), as you can see, is equal to 12.0. That is exactly at the time that I am assigning rpower#()=rpowerhold#(). Yet rpower#() still equals zero after that. I have even tried going this:

rpower#(own,l)=10.0
text 100,100,"rpower#="+str$(rpower#(own,l))

and I still get this on the screen:
rpower#=0

Why oh why

In the inital situation:
own=1
l=1
rdesign=4

This can change, but I know that these values are correct because I use them for other things in the same location, both before and after my problem. I use them when creating the objects and assigning other values, so I know they are correct.

Question:
Are all arrays dimensioned, even if they are something like this:

dimension=0
if dimension=1
dim game(5)
endif

will the array get dimensioned by the compiler? I think they might all get dimensioned no matter what and I may have too many arrays and a random one got deleted, rpower#(). Could this be correct?

Xander Moser of Bolt Software
Firewall: Your Computer's First Defense - Real Time Strategy game
[href][/href]
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 3rd Jul 2004 05:46 Edited at: 3rd Jul 2004 05:53
what do you get if you put

rpower#(1,1)=10.0

text 0100,100,str$(rpower#(1,1))

I am guessing some sublety of code has trashed an index value or tweaked it in some way that isn`t obvious, you could also try adding some empty dummy arrays before and after it and see if that gets things ticking again, I suspect the code, since I have never had this happen or heard of this happening before, and there are a lot of DB projects out there, but creating some other array if it is a compiler problem will hopefully move the problem into that (unused) array, and then the code should start working again.

Mentor.

ps: I THINK the runtime makes arrays on the fly, you could test this by making two bits of code and then printing the memory usage, one that dimensions an array normaly, and one that get made when space is pressed, if the memory usage changes when you press space then they get made on the fly.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster.
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 3rd Jul 2004 13:21
YES!!!

I figured it out, finally! Here was my problem:

When I was trying to make my code a little shorter I was converging some of my lines. Some of them were dim statements. I acccidently stuck the 'dim rpower#(numopp+1,maxbots)' statement at the end of an if then statement. It was still dimensioning the array, but the array was not responding, for some reason. I wish it would have just given me an error instead. Oh well, at least I figured it out.

Thank you for your help, Mentor. Even if you couldn't help me because you couldn't see all my source code.

So, for anybody that has a problem like this in the future:

Don't put dim statements at the end of if then statements when you don't want to

Xander Moser of Bolt Software
Firewall: Your Computer's First Defense - Real Time Strategy game
[href][/href]
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 3rd Jul 2004 21:25
ah! if-then has a mind of it`s own sometimes, I always use if- endif, they give no problem as far as I am aware, sometimes if-then will just inor code or treat as part of the next line, just likes to play up, best avoided where possible.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster.

Login to post a reply

Server time is: 2025-05-24 13:46:57
Your offset time is: 2025-05-24 13:46:57