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 / string array problems

Author
Message
ZoneMaster
21
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United States
Posted: 9th Nov 2004 01:31 Edited at: 9th Nov 2004 02:04
I am working on a 2d text like starship sim (DBC v1.13) that uses a 2 dimensional string array (10,10) set up like this:

x . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .

where 'x' is my ship that i want to move to anywhere in the array.
now i can move the ship fine by inputing 2 coordinates. My problem is, how can i replace the 'old' location (where the ship was) with a '.' without getting an 'array out of bounds' error?

i am using data statements to fill the array initially with data.
click on 'source' to see what i have so far.

2nd in Command,
Executive Officer,
Black Ice Klan [BIK]
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 9th Nov 2004 02:43


Haven't tested it but it should work.
ZoneMaster
21
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United States
Posted: 9th Nov 2004 03:37 Edited at: 9th Nov 2004 05:23
ok maybe i better be a little more specific. I am not using the cursor keys to move the ship. they will be commands input by using
the 'input' command.

input x
input y
sector$(x,y)="x"

now after entering the 'new' coordinates i want to replace the old sector$(x,y) with '.'

ok suppose you start at 1,1 (hypothetical)
works fine going positive like 2,2 or 3,3 and going back to 2,2 and 1,1 as long as you go 1 increment at a time. BUT if you go from 1,1 to 4,4 it doesn't work. I need something that will work for ALL possible coordinates.

If I want to go from sector 1,1 to sector 8,9 it will leave a '.' in 1,1 and put the ship 'x' in 8,9.

OR if I'm at 8,9 and want to goto 3,2 it will leave a '.' in 8,9 and put the ship 'x' in 3,2.

the code you submitted will work fine using the cursor keys but i need it to work for using the 'input' command specifically.

thanks for your reply!

2nd in Command,
Executive Officer,
Black Ice Klan [BIK]
ZoneMaster
21
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United States
Posted: 9th Nov 2004 21:07
never mind i figured it out...quit simple actually

oldx=newx
oldy=newy

input newx
if newx<1 then newx=1
if newx>10 then newx=10

input newy
if newy<1 then newy=1
if newy>10 then newy=10

array$(oldx,oldy)="."
array$(newx,newy)="x"

Thanks for the help!

2nd in Command,
Executive Officer,
Black Ice Klan [BIK]
ZoneMaster
21
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United States
Posted: 10th Nov 2004 09:11
Ok my next problem is HOW do I move multiple objects of the same type in an array. For example...

if i have an array like below 10 by 10
and one object at 1,3 and the other at 5,5

..........
..o.......
..........
..........
..........
.....o....
..........
..........
..........
..........

how can i move them both at once or 1 at a time? I want to be able to move multiple enemies either one at a time or both at the same time.

I CAN get one to move but if there is more than one in the array only one moves the others don't. click on source button.

Hope someone can help

2nd in Command,
Executive Officer,
Black Ice Klan [BIK]

Login to post a reply

Server time is: 2024-11-27 15:41:51
Your offset time is: 2024-11-27 15:41:51