hey im making a game in qbasic and i want to know if i can make global variables so all the SUBs have access to them so i dont have to pass like 50 variables every call. thanks in advance for the help.
hey im making a game in qbasic and i want to know if i can make global variables so all the SUBs have access to them so i dont have to pass like 50 variables every call. thanks in advance for the help.
"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush
Illusion and reality become impartiality and confidence.
i went to that site and posted on the board but i didnt see it on there afterwards. also how do i reply to what someone else posted there? i dont like those kinds of boards very much....
"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush
Welcome to cprogramming.com. We use C and C++ here.
Away.
u forgot c#....
but i figured someone would know qbasic or be able to help me. at least this is a programming board and not, say, a cooking board. and the board is game programming, not specific to any language.
just for future reference, this is my 100th post.
"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush
Then again, the game programming board is under the General Programming Boards category, not C(++, #) Programming Boards section.
Let's be nice to him.
Now I have very little knowledge of QBasic. Just enough for my QBasic class in school. . But I believe if you declare variables outside a SUB then it is global.
Like this:
I'm thinking that StringOne$ is global. Or is it not?Code:CLS StringOne$ = "This is string one." END
well if i declare them as constants they work, but otherwise they dont. thats a step in the right direction, but i need them to not be constant. any other ideas?
"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush
sorry for bumping this up, but i couldnt edit (its been more than 1440 minutes)
i finally figured out how to make the global though, and i wanted every one to know,
DIM SHARED variables(x)
then just store the vars in there. i use constants to reference certain cells (ie i have CONST STRENGTH = 1; CONST DEFENSE = 2; et al, and then if i need to see their strength i just do PRINT variables(STRENGTH))
thanks for the help though (or lack there of, in some cases )
"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush
That's a rather inefficient method if you just want to store individual variables.Originally posted by Geo-Fry
[B]sorry for bumping this up, but i couldnt edit (its been more than 1440 minutes)
i finally figured out how to make the global though, and i wanted every one to know,
DIM SHARED variables(x)
then just store the vars in there. i use constants to reference certain cells (ie i have CONST STRENGTH = 1; CONST DEFENSE = 2; et al, and then if i need to see their strength i just do PRINT variables(STRENGTH))
The correct syntax for global variables is:
Just plug in your global variables in a COMMON statement at the top of the file.Code:COMMON global1, global2, somevar3, somevar4
Hope that helps!
COMMON is only used if you are sharing variables between
QBasic programs. Since QB progs have a 64KB limit and are all in the small memory model, I can't see much use for it myself. COMMON helps in VBDOS so that your forms know about certain variables. I normally use the DIM SHARED or CONST to declare global variables.
QB is not nearly as elegant in dealing with multiple file or multiple module programs as C/C++.