Qbasicnews.com
Does this work? - 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: Does this work? (/thread-3183.html)

Pages: 1 2


Does this work? - Weasel88 - 02-12-2004

Im making a text-based RPG and i have made an simple level-up system for it... now i wonder if it works...

IF experience$ = "45" THEN
level$ = level$ + 1
Attack = Attack + 4
Defence = Defence + 2
Magic$(0) = "flare"
CLS
PRINT "Level up""
PRINT "Gained some stats and learned magic flare"
SLEEP
CLS
GOTO PlayerX, PlayerY


Does this work? - KiZ - 02-12-2004

ok, that looks ok, but a few suggestions.

1. The first line should be
Code:
IF experience > "45" THEN
it is always good practice, because if you are adding decimals, then it can go past 45 without actually being 45 if you see what I mean.
And dont have the $ at the end. It isnt used for holding text.

2. You are using a variable level$. Dont. If this variable is meant to hold numbers, dont have the $ at the end. That signifies that it is a string, used for holding Text.

3. What do you mean by this?
Code:
GOTO PlayerX, PlayerY

GOTO means to goto a certain place in the program, not locate the cursor at position PlayerX, PlayerY.

if you are wanting to position the cursor, use:
Code:
LOCATE PlayerX, PlayerY

Otherwise, it looks ok. Wish you luck on your project. Tongue


Does this work? - Weasel88 - 02-12-2004

ops... hehe... sorry... that
GOTO PlayerX, PlayerY was another question...
how do i make so when u gain a level and the lvl up message is shown, how do i make so it will go back to where u was before u leveled up..


Does this work? - Weasel88 - 02-12-2004

ops... sorry for my bad english... no good at it


Does this work? - TheBigBasicQ - 02-12-2004

You're worse than a translator. Anyway there are two answers to your question:

1. Use GOSUB
2. Use SUBs

Now, GOSUB is a small set of instructions which are written inside the program body. For example:

PRINT "my name is foo"
GOSUB printsomething
PRINT "I am back!"

END

printsomething:
PRINT "I printed something"
RETURN

You should always write GOSUB after the "END" statement to prevent accidental execution of the code.

Second answer is my choice. I would use SUBs rather than a GOSUB. SUB is a different sub-program(a small program inside the program) also known as SUB-ROUTINE.

A sub has three parameters to be defined:
1. The Sub-name
2. The return type
3. The arguments

example: FUNCTION MYSUB%(arg1$, arg2%)

MYSUB = name
% characterises that it will return an integer
and arg1$, arg2% are the arguments

FUNCTION MYSUB%(arg1$, arg2%)
PRINT arg1$, arg2%
RETURN 0
END FUNCTION

when you want to call a sub you just type:

returnedval% = MYSUB%("foo", 56)

Thats also known as a function.

PRINT "my name is foo"
temp% = MYSUB%("blah", 342)
PRINT "I am back!"

You see both SUB and GOSUB allow your program execution to continue after they have finished performing their function =).


Does this work? - KiZ - 02-12-2004

Quote:You're worst than a translator.

Worst than???

who's bad at english?!

nah, j/k =D


Does this work? - TheBigBasicQ - 02-12-2004

My mother tongue isnt English but i am pretty good at my spelling and grammer.


Does this work? - na_th_an - 02-13-2004

Quote:grammer.

It is grammar Wink

In Spanish we call this "ir de enterao".


Does this work? - oracle - 02-13-2004

nath picking apart somebodies english? Naah, can't be! :lol:


Does this work? - na_th_an - 02-13-2004

I just nitpicked him 'cause he was nitpicking Tongue

I just found funny someone writing "i am pretty good at my spelling and grammer" and misspelling "grammar" (no offence intended!).