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 / A Problem With Data-Read and Arrays

Author
Message
Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 19th Aug 2003 06:04
In the code area, I've provided a limited text-based RPG that works for the most part. My problem is, after you win the first fight and start the next, the monster has no name and no stats. I know the problem is when the program reads the data statments with the stats in them, but the fact that it works the first time, but dies the second time, confuses me. Usually, if something won't work, it dies the first time, yeah? I'm hoping this doesn't turn out to be some kind of DBPro flaw or limitation, or I'm going to end up changing a ton o'code. Please help me!

P.S. Hope it works right for you all when you use it. I usually keep all the functions in a seperate file for organization's sake. And if you need more information as to what a certain area of the code does, just ask!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 18:09
Without reading your code I am pretty sure I remember that when you read a set of data statements the DB Engine keeps track of where the "cursor" is, in order to re-read data there is some command to bring the cursor back to a particular location -look in the dbp help under data statements.

gl

-RUST-
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 18:10
RESTORE me thinks

-RUST-
Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 19th Aug 2003 19:07
And that would be where my problem is. So you don't have to look at my code, I'll just show you where the main problem seems to be

rem Randomly choose the monster
randomize timer()
WhichMonster=rnd(4)+1

rem Restore Based on WhichMonster Variable
if WhichMonster=1 then restore Monster1
if WhichMonster=2 then restore Monster2
if WhichMonster=3 then restore Monster3
if WhichMonster=4 then restore Monster4
if WhichMonster=5 then restore Monster5
WhichMonster=0

read MonsterStats(1).Hp,MonsterStats(1).MP,etc

as you can see, I use the restore command, but perhaps improperly. Basiclly how the code is supposed to work is every fight, the variable WhichMonster is assigned a random number between 1 and 5, the the if statements restore a specific label based on WhichMonster. Which Monster is then reset to zero and the data is read. This actually works quite well the first time, but the second time, nothing is loaded. I've done a stepthrough of the program, and the WhcihMonster Variable is being assigned a number, but it seems that either the restore or the read are not working right. An odd glitch indeed!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 19:28
I am pretty sure you are using RESTORE incorrectly...

from dbp help:
RESTORE
This command will reset the DATA statement pointer to the very first piece of data in your program.
Optionally, if you specify a label, it will reset to the DATA statement immediately following that label. To
create a DATA statement label you must write a label in your program followed by a sequence of DATA
commands. The label can be made up from any combination of alphabetic characters, but you must end
the declaration of the label using a colon(. You only need to use a colon when you are declaring the
label, and a colon should not be used when calling the RESTORE command

so either just RESTORE to set pointer to first DATA statement in prog or hide your DATA statements in Labels and set the pointer to a specific set of DATA statements like...

MyDataBlock_A:
DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MyDataBlock_B:
DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DATA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

call with....
Restore MyDataBlock_A

-RUST-
Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 19th Aug 2003 20:46
rem Monster Data's
Monster1:
data "Creeper",1,100,25,29,11,8,4,5,2,9
data 49,49,10,10,38,18,17,3,26,24,4,5,4
Monster2:
data "Nasty",2,175,32,36,14,9,5,6,3,11
data 77,77,15,15,45,25,20,3,34,28,5,6,5
Monster3:
data "Uglyness",2,225,29,45,10,12,12,9,7,7
data 35,35,54,54,60,40,19,10,27,28,12,9,6
Monster4:
data "Foul Odor",3,275,34,49,6,10,2,2,24,17
data 51,51,2,2,31,11,27,10,23,21,2,2,5
Monster5:
data "Gas Cloud Of DOOM",3,305,39,54,7,12,3,3,24,18
data 63,63,4,4,42,22,30,12,25,25,3,3,6
MonsterTheBoss:
data "A Really Scary Monster",4,500,52,143,17,18,1,1,1,20
data 170,170,1,1,77,57,38,18,32,39,1,1,9

These are the data statements my program refers to when using the restore command and then reading. Each has a label (Monster1:,Monster2:,Etc.) that, when the restore command is invoked, ends up pointing to THE FIRST TIME AROUND. Each time I run the program, the program restores to the correct label, then procedes to read the the correct data and sets it to the Arrays. The inforamtion in the arrays is then printed to screen. The problem is after you defeat a monster and the program loops back to the beginning, but when it reaches the point of reading new data into the array, so as to allow a new monster take you on, it loads empties. No name or stats, just 0s and blank spots. This is the problem I have been unable to solve. Any Ideas?
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 19th Aug 2003 22:10 Edited at: 19th Aug 2003 22:15
just had a play, it does seem as though the types are to blame, if you reset the pointer then read A$ and print it then reset the pointer again, you can`t get any data from the types, BUT if you play the beast and then then let it loop round then the next monster gets read, so it looks like the types are the problem, you can get empty types like that if you read out of sequence IIRC, ie you may be reading a string when it should be a number, but why it works the first time round I don`t know, as soon as you read data, you can`t load it into the types again, even if you restore the pointer, I never had this problem since I use explictly named variables, I`m to old to be bothered with all this types rubbish , heres the mod I made, just cut and paste this in instead of what you have, play it through a few times and keep your eye on what is being printed in the top left of the screen, you can see the data is still getting read, it just isn`t getting as far as the types, maybe you could use temporary variables and get it to work that way, cheers.

Mentor.

ps: stick a routine in to make the code ignore case, would, make the input far easier, you could then just type attack instead of Attack

Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 19th Aug 2003 23:49
To Mentor: Blast! That's likely the source of my problems. With all those Integers, I stuck a string in there, and according to my father, whom knows several web languages and Visual Basic to boot, Arrays are supposed to only carry one type of Data Type. But before I give up on this, I'm going to try a few different ideas, as soon as I get beck in fornt of my own pc. For instance, perhaps if I unmade the array, then recreated in a loop, I might be able to repeat what might be a glitch, allowing me to keep this as is. As is, I'm going to send an email to Tech Support and see what they say. I'm hoping this will just be a case of having to changing certain pieces of the code, I'm dreading the idea of having to redo a chunk of code, although if that is what becomes necessary, than I will do as nescessary.

One question though. What is a$? It's nowhere in the manual for DBPro, and it seems like a regular variable, but it calls on the first Stored variable as if it were some form of command! Baffeling!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 23:58
Ok, Mentor has pinpointed the problem. from VB experience you can't mix an array with diffent data types, so I expect that if this is happening somewhere in your code - that would be the problem of no data loading after first time...DBP really needs to flag these issues better, it seems we coders run in circles with silly sh*t that the IDE should be pointing out straight away.

If you make an array of INTEGERS, and somewhere in your code you are saying MyIntArray(xx)=SomeStringVariable It shouldn't even compile!

just MHO

-RUST-
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 20th Aug 2003 00:03 Edited at: 20th Aug 2003 00:17
I think you misread the code, it`s just a regular string variable called a$, I loaded the string data into it with read (since it was a problem with types I know that normal vars work ok since I use em all the time alongside data and restore) when the restore occured and then afterwards restored again with the same value for monstertype or whatever it was so it was reset for the read you had coded, so that the first read was of the first bit of data (the string), cos reading a$ and then just letting it continue would have tried to load a variable into the string and caused an error, I don`t use types myself (to old to change), it`s a pity the editor has such weak checking, theres a lot of stuff it could flag as an error with better checking and save time for us hacks .

Mentor.

Rwilson
21
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 20th Aug 2003 07:03
Mentor: Agh, your right, it is just a variable. Must have been a tad out of it at the moment to miss that.

Mentor & CattleRustler: YEs it would be nice of the IDE to point such things out. And as soon as I get my e-mail working again, I'll be informing the DPPro Tech Support of that. Although, I have noticed something odd. The second data command is full of nothing BUT integers, so unless it's getting stuck on the bad data-variable, it should be putting that up. I'm at home now, so I should be able to play with the code now.

Login to post a reply

Server time is: 2024-11-25 04:56:39
Your offset time is: 2024-11-25 04:56:39