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 / Saving a string from input

Author
Message
GameFreak4
14
Years of Service
User Offline
Joined: 15th Oct 2009
Location:
Posted: 3rd Nov 2009 19:49
Hi everyone!

I'm trying to make a code that will prompt player for his/her name,save it under a string calles Name$ and write that ina .dat file.I have wrote following code:



The problem is that the file it writes is blank.Can anybody tell me how to do this properly?

My version of DBPro is a free one.
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 3rd Nov 2009 20:07
Name$ in your function is local to the function and a separate entity to the one used outside it (empty when you save it).

To be frank, you simply don't write programs like that. You may get away with it while you are writing programs of 20 or less lines, but most of the time it simly won't work.

Check out 1 to 4 here:

Tutorials For Beginners

TDK

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 4th Nov 2009 19:08
Now you most definitely should read all of TDK's tutorials but the quick answer is Name$ needs to be set to GLOBAL for it to work inside functions.

The major problem with your code (the thing that probably caused TDK to say "you simply don't write programs like that.") is that normal code (anything not in a function) is placed at the top, then an "end" so hitting a function doesn't cause an error, then any functions at the end of the code. Functions cannot be in the middle as you have done. The "wait key" at the end will never, ever be seen.

Another problem is that even though you know whats going on (being the programmer) you need to inform anybody else running it to know what you're wanting. Add a "What is your name? " in the INPUT so people won't be scratching their heads looking at a blank screen.

There's no need to wait 2 seconds after it saves... unless the goal is to annoy people.

There's no need to SYNC since there is no SYNC ON. The default setting will update the screen anytime there is a change. There is also no need for multiple WAIT KEYs. When a function is called it does it's thing and always goes back to the next line after the function call. You can put one WAIT KEY under SaveGame() to achieve the same results as multiple WAIT KEYs in an IF statement.

But don't worry about the WAIT KEYs in the function because the way the code is written there's really no need to do a check in the function to see if the file was written properly. An unproper save would mean your hard drive failed or some other major problem that has nothing to do with code. Just cut out that check and rest assured that it will work no matter what.



Login to post a reply

Server time is: 2024-09-28 12:19:47
Your offset time is: 2024-09-28 12:19:47