Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / read string data

Author
Message
nnndohh
18
Years of Service
User Offline
Joined: 12th Aug 2006
Location: netherlands
Posted: 21st Jul 2011 22:51 Edited at: 21st Jul 2011 22:54
first of all, since i know of the excistance of darkbasic i'm very interested in programming, now years later, i still suck at it.

while reading through " hands on darkbasic pro" for the second time i had to type some test code for the hangman game.
the weird part is, it doesn't work at all, double checked the code.
another weird part is, it only works if i put a " print word$ " after " next c"
why doesn't it work right out of the book?

Rem Project: testhinkofword
Rem Created: Wednesday, July 20, 2011

Rem ***** Main Source File *****
randomize timer()
thinkofword()
print word$
wait key
end

function thinkofword()
data "london","glasgow","blackpool","edinburgh"
data "boston","berlin","moscow","sydney"
data "wellington","washington","rome","amsterdam"
data "stockholm","oslo","lisbon","madrid"
data "prague","bonn","budapest","vienna"

num = rnd(19)+1
for c = 1 to num
read word$

next c


ENDFUNCTION


and please excuse me, don't know how to post code snippets, i see when i post a "code" button, but it does nothing but putting a [CODE] in my post
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 22nd Jul 2011 00:04
That [ CODE ] goes at the start of your code, and the [ /CODE ] tag goes at the end (I put extra spaces in there to see the tag.)

As far as your code, you don't declare word$ as global, so your program is essentially using two versions of it - one local to your main code, and one local to the function. On page 239, the first instruction listed is



Simply add that to your code to make word$ a global variable that your function can access.

nnndohh
18
Years of Service
User Offline
Joined: 12th Aug 2006
Location: netherlands
Posted: 22nd Jul 2011 00:24
geeez , i forgot that line, thanks man
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 23rd Jul 2011 07:23
I've seen some forum posters posting coloured code when using the code feature on these forums?

How is this done?

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Jul 2011 08:18
It's the standard code snips but with "lang=dbp" added to it.

Remove the end spaces from this:
[ code lang=dbp ]
` This is in color
print "Hi!"
wait key
[ /code ]

And it'll do this:


Login to post a reply

Server time is: 2024-11-22 18:46:08
Your offset time is: 2024-11-22 18:46:08