• Can't get map program to work
    8 replies, posted
Before I get into this let me explain something. Yes I know Qbaisc isn't the best thing out there. 2nd I only know very little about programming. No bitching about me using Qbasic or any other non-helpful remarks. I've been at this for about 3 hours now. [code]CLS DIM A(5, 4) FOR B = 1 TO 5 FOR C = 1 TO 5 READ A(B, C) NEXT C NEXT B DATA 0,2,3,0 DATA 1,0,5,0 DATA 0,4,0,1 DATA 3,5,0,0 DATA 4,0,0,2 A(1, 1) = 0 A(1, 2) = 2 A(1, 3) = 3 A(1, 4) = 0 A(2, 1) = 1 A(2, 2) = 0 A(2, 3) = 5 A(2, 4) = 0 A(3, 1) = 0 A(3, 2) = 4 A(3, 3) = 0 A(3, 4) = 1 A(4, 1) = 3 A(4, 2) = 5 A(4, 3) = 0 A(4 ,4) = 0 A(5, 1) = 4 A(5, 2) = 0 A(5, 3) = 0 A(5, 4) = 2 RO = 1 10 PRINT "YOU ARE IN ROOM NUMBER "; RO IF A(RO, 1) <> 0 THEN PRINT "A DOOR LEADS NORTH" IF A(RO, 2) <> 0 THEN PRINT "THERE IS AN EXIT TO THE SOUTH" IF A(RO, 3) <> THEN PRINT "YOU CAN LEAVE VIA THE EAST EXIT" IF A(RO, 4) <> THEN PRINT "A DOORWAY OPENS TO THE WEST" INPUT "WHICH DIRECTION"; D$ IF D$ = "N' AND A(RO, 1) = 0 THEN PRINT "YOU CANNOT MOVE THAT WAY" IF D$ = "S" AND A(RO, 2) = 0 THEN PRINT "YOU CAN'T WALK THROUGH WALLS" IF D$ = "E" AND A(RO, 3) = 0 THEN PRINT "TRY ANOTHER DIRECTION" IF D$ = "W" AND A(RO, 4) = 0 THEN PRINT "THERE IS NO DOOR TO THE WEST" IF D$ = "END" THEN END GOTO 10 [/code] And thats about it. I want to make were I can walk around but I don't know how to make RO (Which is the room your in) change. Please help!
Ahmahgawsh QBASIC!!! Its been at least 10 years since I have even heard the mutter of that name, let alone used it. (Was my first programming language, so this brought a smile to my face :P)
I'm surprised people still use Windows 95! To change RO just use RO = number or something. Sorry, I don't remember much about QBasic, it has been far too many years.
I don't think his problem is assigning the value, since he is already doing it in his code. Here's my guess at the logic you are looking for. Didn't try it, just googled the QBasic syntax real quick. [code]IF D$ = "N" THEN IF A(RO, 1) = 0 THEN PRINT "YOU CANNOT MOVE THAT WAY" ELSE RO = A(RO, 1) ELSEIF D$ = "S" THEN IF A(RO, 2) = 0 THEN PRINT "YOU CAN'T WALK THROUGH WALLS" ELSE RO = A(RO, 2) ELSEIF D$ = "E" THEN IF A(RO, 3) = 0 THEN PRINT "TRY ANOTHER DIRECTION" ELSE RO = A(RO, 3) ELSEIF D$ = "W" THEN IF A(RO, 4) = 0 THEN PRINT "THERE IS NO DOOR TO THE WEST" ELSE RO = A(RO, 4) ELSE PRINT "ONLY N/S/E/W ALLOWED" END IF[/code]
[QUOTE=Dienes;34513224]I don't think his problem is assigning the value, since he is already doing it in his code. Here's my guess at the logic you are looking for. Didn't try it, just googled the QBasic syntax real quick. [code]IF D$ = "N" THEN IF A(RO, 1) = 0 THEN PRINT "YOU CANNOT MOVE THAT WAY" ELSE RO = A(RO, 1) ELSEIF D$ = "S" THEN IF A(RO, 2) = 0 THEN PRINT "YOU CAN'T WALK THROUGH WALLS" ELSE RO = A(RO, 2) ELSEIF D$ = "E" THEN IF A(RO, 3) = 0 THEN PRINT "TRY ANOTHER DIRECTION" ELSE RO = A(RO, 3) ELSEIF D$ = "W" THEN IF A(RO, 4) = 0 THEN PRINT "THERE IS NO DOOR TO THE WEST" ELSE RO = A(RO, 4) ELSE PRINT "ONLY N/S/E/W ALLOWED" END IF[/code][/QUOTE] Are you assigning the rooms to which direction you go? [editline]2nd February 2012[/editline] My problem is that RO is the room your in. When not assigned anything it says your in room 0 which doesn't exist. But if I make it were RO= 1 then I'm all was in room one, which makes no-sense.
Well, I interpreted your array as A(room, direction) = adjacent_room so I lookup what room the player will end up in and update the current room variable (RO) accordingly. [editline]2nd February 2012[/editline] [QUOTE=Jacob_sword;34515268]But if I make it were RO= 1 then I'm all was in room one, which makes no-sense.[/QUOTE] Not sure what you mean. It is indeed correct if you're in room 1 at the beginning. Then the user types "E" and we check the array for (RO, 3) where RO is the current room number 1 and 3 results from choosing "E". What we get from the array is 3, which means the player moves from room 1 to the east into room 3, so we update RO with 3 and rinse, repeat...
[QUOTE=Dienes;34515356]Well, I interpreted your array as A(room, direction) = adjacent_room so I lookup what room the player will end up in and update the current room variable (RO) accordingly. [editline]2nd February 2012[/editline] Not sure what you mean. It is indeed correct if you're in room 1 at the beginning. Then the user types "E" and we check the array for (RO, 3) where RO is the current room number 1 and 3 results from choosing "E". What we get from the array is 3, which means the player moves from room 1 to the east into room 3, so we update RO with 3 and rinse, repeat...[/QUOTE] That right there is my problem! I try to go into a new room the thing says I'm still in the first room. Question How does RO know what room your in? I think that might help. Because when I set up the array nothing goes to RO.
[QUOTE=Jacob_sword;34515562]How does RO know what room your in?[/QUOTE] Basically everywhere you use RO (except when assigning it a value) you do things according to the current room. [code]RO = 1 ' you tell the program that you are in room 1 PRINT "YOU ARE IN ROOM NUMBER "; RO ' you check in which room you are and alter the message accordingly IF A(RO, 1) <> 0 ' you check if the current room has an exit to the north etc.[/code] [QUOTE=Jacob_sword;34515562]I try to go into a new room the thing says I'm still in the first room.[/QUOTE] Okay, if THAT is happening, I guess your goto statement is misbehaving and the line "RO = 1" is executed everytime you jump back. Well, I (and everyone on earth) highly discourage the use of goto anyway. Try to wrap a loop around instead, see if it helps.
[QUOTE=Dienes;34515745]Basically everywhere you use RO (except when assigning it a value) you do things according to the current room. [code]RO = 1 ' you tell the program that you are in room 1 PRINT "YOU ARE IN ROOM NUMBER "; RO ' you check in which room you are and alter the message accordingly IF A(RO, 1) <> 0 ' you check if the current room has an exit to the north etc.[/code] Okay, if THAT is happening, I guess your goto statement is misbehaving and the line "RO = 1" is executed everytime you jump back. Well, I (and everyone on earth) highly discourage the use of goto anyway. Try to wrap a loop around instead, see if it helps.[/QUOTE] Ok I'll see what that does. Also thanks for the help man really appreciate it.
Sorry, you need to Log In to post a reply to this thread.