PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

BASIC Help

Here's my very basic code dealing with the random number generator. I want it so that when the user inputs break or Break the app will jump to label 2 and then end itself. However, all it does is add a random number to the end of Break. Also, the random number generator appears to only create a random number > .0. Any ideas?

Here's my code:

Label 1
randomize 1
input A
if A=Break|break then goto 2
A=A+RND
print A
goto 1

label 2
end

| means "or"
You probably want something like:

if A=Break or A=break then goto 2

As for the random thing, it could be that the RND function gives you a value between 0 and 1 and expects you to multiply it into the range you'd like?

I.e. to add between 0 and 10 to A:

A=A+(RND*10)

(Which BASIC variant is it - a calculator or something?)
Further to refractor's answer, a random number between a and b can be generated thus:

RND * B + a

eg, between 6 and 13:

RND * 13 + 6
I'm using SmallBASIC.

http://smallbasic.sourceforge.net/


Thanks for the help with the RND function. I still however can't get it to do anything with Break or break. It still adds a random number to the word.
INPUT A
PRINT A,Break,break

RUN see what you get, guessing 0,0,0.

Find out what your dealing with. Suspect Break=0 as a default setting for initialising the variable. It'll be an ASCII(4 maybe EOD) value or more likely default to zero again if not set. You've got the whole INKEY or KEY and build your own input emulator if it won't tell you Break. Better way is $ input and check ="" or else EVAL.

In most basics with a fractional RND.
num=((13-6)*RND)+6
to get 6<= num <13 results
INPUT A
PRINT A,Break,break


returns: 0 0
So you hit break on the INPUT a and it returned nothing. Haven't seen behaviour like that since the Sinclair QL automatic string-numer thing which had a very technical term.

Can you
INPUT A
IF(A="") PRINT "Batman"

See if it spits on the "".
I had to add a "then" to it otherwise it refused to let the PRINT come on the same line after the IF.


Here:

INPUT A
IF A="" THEN PRINT "Batman"

Returns: Batman
Okay so what they are writing is a basic with automatic string to number coercion.

as in
FOR B=1 TO 10
C=B+" men on the piss"
PRINT C
NEXT B

Just use the A="" as a null input to do the thing you were going to do.

Code:
Label 1
randomize 1
input A
if A="" then goto 2
A=A+(RND*100)
print A
goto 1

label 2
end
I did this:

Code:
LABEL 1
RANDOMIZE
INPUT A
IF A="" THEN END
A=A*(RND*50)
PRINT A
GOTO 1


Basicly, I'm hoping to build up to making a game of sorts.
Beyond guess a number, higher or lower it might be too much of a pain. You can do a reasonable job of a text adventure old style

PRINT "You enter a room, the Ravens sing a chorus of doom over the corpses laid across the floor."

INPUT "What " A
IF A="N" GOTO cave.
IF A="E" PRINT "You cant go there."

etc, but there are tools for writing interactive fiction that would serve you better. Quite like an RPG. :wink:
A text-based game was what I had in mind. I wanted to make a clone of an old DOS game I played years ago called "Empire". There is a Palm OS version with a GUI out. You can find it <a href="http://coindepalm.studel.fr/eng/index.html">here</a>
GUI sais to me embedded C++ or Basic. Downloaded the zip from the guys site: The images must be from a manual as they are filled in with names and values.

What the other countrys would need to do in artificial intellegence is to create an imagination of what could happen. Just an array. Try out options that the normal player could do. Then see which at the current moment has the best result. It wouldn't have to take them and do them again and then build it really effeciently like a chess or even draughts program to consider 10000 alternatives a go.

Although basic could do everything you need you want a compiled one with the ability to make boxes and deal with the input. Embedded visual basic is your thing. This basic would be for programable calculator like things. Maybe PPL.

Good luck!
Since I'm starting on this game now, I was wondering what is the proper development cycle for a game? what should I try getting up and running first?
In general don't know. Here is a rambling version.

This game as described.

Number balance in this game. Setting for taxes? Number of Army?.

So at the heart of your game is a spreadsheet table. Some values a player would see. Some they would not. There are no facts you are God making the equations. With values that create possibile tactics. Write down all the features of an economy you can put a number to.

Business.
Mines need cheap labour from the same class who soldier.
Manufactures need disposable income.
Services need progress.

Army.
Needs to get paid.
Needs to replace dead soldiers.

etc.. etc.. all paper and pen stuff.

Then you need to come up with the paradigm that allow different tactics to produce viable nations succeeding. Think of Nuetral trading nations, Agressive trading nations, aliances and empires.

Once all of that comes down to a paper calculation that shows promise but needs minor adjustment. Translate the whole thing to computer.

Then start building the GUI. If you build the GUI first in this kind of game you will code far more than you need to. Much will get editted and deleted.


In stages

Stage one) Boring table of values, getting to understand yourself how you would beat the game and what makes the game fun.

Stage two) Encapuslate what you are doing on paper as a set of table based calulations, that is easy to do on the computer.

Stage three) Wrap it all up. What is the perfect economy. What total of this table gives a single number to measure everything. Then the program need only compare increasing and decreasing things it has control of and search for how to make that number bigger. It is unlikely that number is the score each nation has.

Stage Four) Give your self control of changing some numbers. Review what you have done.

Stage Five) Make a GUI anyone can change the numbers and write the instructions.

Stage Six) Beta release.