Click to See Complete Forum and Search --> : 2 questions for my little test like rpg thing
timmy
Nov 26th, 2001, 04:02 AM
hey im faiiirly new to vb and im making a little rpg thing.
anyway i was wondering how would be best to save characters and how to do it?? i mean like .ini files? .dat files?? how do i do that?
annd one more thing, keypresses dont seem to work, i mean ive tryed the 'Form_KeyPress' and the 'Form_KeyDown', doesnt seem to want to work. the form that im working with has a main frame with some pictures in it and two text boxes on the form as well (a lil console type thingy). it just doesnt want to work for me, anyway im just trying to get the arrow keys going for now if thats anything.
anyway any help would be heaps apreciated, hope all that made sense.
thanks
tim :D
Osiris
Nov 26th, 2001, 11:34 AM
the way i look at it, is that if your going to make a file for a saved
game, dont save it in as an ini file, you can make up your own
like "save.me" could be a file, that way the user wont be able to
cheat by changing things in the ini file, well, they'll be able to
change them in the "save.me" file, but it'll be harder :D
well, keypress and keydown dont work for you because you said,
you have textboxes, pictures, and frames on your form, and thats
taking the focus away from the form, and the only way keypress
and keydown work is when they have the focus...
timmy
Nov 27th, 2001, 03:05 AM
hey thanks for the reply, i was kinda hoping for some code for using files, just i dont know how to create and save to files and stuff :confused:
Zaei
Nov 27th, 2001, 06:30 AM
There are tutorials on this site (take a look at the nav bar at the very bottom). You should find all you need there.
Z.
timmy
Nov 28th, 2001, 07:29 AM
hey thanks, i can use files now..
another thing though
is there a decent way to generate random numbers?
i mean is (Rnd * 750) for instance a good way to do it?
because i dunno, either its just me or im getting the same numbers EVERY single time being generated
anyway thanks
:D
drewski
Nov 28th, 2001, 04:00 PM
Timmy, to make it so that KeyPress and KeyDown will always work even if you have controls on the form all you need to do is set the Keypreview to true. This way you won't have to keep switching the focus between the form and the controls.
Here's the formula to create random numbers:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Uppperbound is the highest number you want the random number to be and lowerbound is the lowest number the random can be.
The reason why you always get the same number when making your random number is that Rnd keeps the value it has the first time its called. If you want to call Rnd again for a new random number use the Randomize statement.
Randomize
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
These two lines of code will create a brand new random number each time they are run. Just make sure to fill in the variables :)
Hope this helps.
Drewski
timmy
Nov 29th, 2001, 04:11 AM
hey thanks heaps drewski
thats been a HUGE help
:D
Zaei
Nov 29th, 2001, 06:38 AM
Generally, you should call Randomize only ONCE per application.
Rnd() will always produce the same random values. For instance, create a form, and add a list box. On Form_Load, use this code:
Randomize 0
dim i as integer
for i = 0 to 10
list1.additem cstr(rnd()*100)
next i
Every time you run that program, you should get the same values.
This fact was used in games like Elite, to create infinite universes. The only thing that then had to be saved for a saved game was the seed value used to create the universe, because using that seed, the same series of numbers could be re-generated.
Z.
timmy
Nov 30th, 2001, 07:10 AM
thanks zaei
another question though (i figure i may as well keep posting in this thread :D )
say i want to have a listbox with all my savegames being listed..
how could i get the listbox to display all the '.tim' files in a directory so i can load the files and etc...
thanks
Zaei
Nov 30th, 2001, 08:52 AM
It would be easier to use the Common Dialog Control (Something like Microsoft Common Dialog Control 6.0, or something in the components section). It will give your application a sense of familiarity to users. Most all windows programs use it, or the API call equivelent.
Z.
Sastraxi
Nov 30th, 2001, 02:45 PM
There's a great arcticle here with a full module (!) that contains the code to make the Common Dialog with API calls, shaving hundreds of kilobytes off the finished product.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.