Qbasicnews.com
Duplicate Label ?! - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: Duplicate Label ?! (/thread-184.html)



Duplicate Label ?! - NovaProgramming - 02-09-2003

HEy guys, this is probably a very simple problem with a very simple answer, but, I am trying to make an RPG game that allows the user to save in binary to three slots... so...

Open Slotsave1 FOR BINARY AS #1
PUT #1 , , playername$
PUT #1 , , playerlevel
PUT #1 , , strength
CLOSE #1

right?

But, when I say something like:
PRINT "Choose a slot to save"
input slot
if slot = 1 then goto saveinslot1
if slot = 2 then goto saveinslot2
if slot = 3 then goto saveinslot3

saveinslot1:
Open Slotsave1 FOR BINARY AS #1
PUT #1 , , playername$
PUT #1 , , playerlevel
PUT #1 , , strength
CLOSE #1

saveinslot2:
Open Slotsave2 FOR BINARY AS #2
PUT #2 , , playername$
PUT #2 , , playerlevel
PUT #2 , , strength
CLOSE #2

and so forth, but then it says on the variable 'strength'

DUPlICATE LABEL

or something like that. I use this at the top

DIM SHARED strength AS INTEGER

do I need to put something else at the top... like
'$DYNAMIC
or
DEFIN A-Z I think that's it, but maybe not

anyway, it gives me a duplicate label error message whenever I try to do that, so I guess, is it only possible to save to one slot?

Any help would be appreciated, uh, if this doesn't make sense email me or post a message

NOVA@EDGEEMU.COM

thanks


Is the variable "strength" used in any subroutines - Glenn - 02-09-2003

If it is but it's supposed to be a completely different variable than the one in the main routine, take out the "SHARED" attribute in your DIM statement. (And if "strength" doesn't need to be a global variable, you don't need the "SHARED".) Generally, that error message means that you're trying to reuse/redefine a variable that's already had its type specified.


Duplicate Label ?! - na_th_an - 02-09-2003

It sounds like a side effect, it isn't definitely a problem of wanting to save in several slots.

Check that you are not using the same name for an array and for a label, and that you are not using the same name for arrays/variables of different types.

In QB, identifiers must be unique. Check your program carefully.


Duplicate Label ?! - Agamemnus - 02-09-2003

If you dim a variable AS something, you can't use the same name with a different type:

Code:
CLS
'DIM a AS INTEGER
'a = 6
a% = 5
a! = 500000000
a$ = "5"
a# = .5
a& = 50000
a: PRINT a; a%; a!; a$; a#; a&

Uncommenting a = 6 sets a% and a! to 6. Uncommeting the DIM only allows you to set a% = 5.


We said that already :) ... - Glenn - 02-09-2003

Quote:If you dim a variable AS something, you can't use the same name with a different type:

Code:
CLS
'DIM a AS INTEGER
'a = 6
a% = 5
a! = 500000000
a$ = "5"
a# = .5
a& = 50000
a: PRINT a; a%; a!; a$; a#; a&

Uncommenting a = 6 sets a% and a! to 6. Uncommeting the DIM only allows you to set a% = 5.

The question is, where's he reusing "strength"?


Duplicate Label ?! - NovaProgramming - 02-12-2003

ok, so what I am doing is:
using strength to represent the player's strength alone (it is an RPG), notincluding the weapon's power.
whenever I try to put anything as an integer...
it comes up with a dupilcate label error and stuff like that...

umm

so there is other integer values... such as weaponpower armordfc bootagl and stuff like that that are also coming up with error messages.

When I asked how to save a game (a long time ago) Na_th_an told me that I should save it as a binary like so
OPEN saveslot1 FOR BINARY AS #1
put #1,,

and so on
but whenever I do that for the integers it always comes up with 'dupilcate error' so...
I am wondering if it matters if strength is DIM(ed) and then set as an integer or something like that. Actually, I am talking out of my butt, I don't know what I am saying. Later I will obtain some source copy (I can't right now) so you guys can see it, but for the current time just help me out if you can... thanks again.


Humor me... - Glenn - 02-12-2003

Run this simple program:

DIM STRENGTH AS INTEGER
STRENGTH=&H4241
OPEN "STRENGTH.TXT" FOR BINARY AS #1
PUT#1,, STRENGTH
STRENGTH=&H0A0D
PUT#1,, STRENGTH
CLOSE #1
END

Then use notepad or some other text editor to look at the file STRENGTH.TXT. You should see "AB". Let me know what happens.