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 / For/Next Loop

Author
Message
Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 2nd Aug 2008 07:27 Edited at: 2nd Aug 2008 07:38
i'm still working on the text-based RPG.

i'm trying to cut the code down some and had an idea how. problem, like all my ideas, i can't get it to work.

here's what i have that works:


9 races, 12 weapons, and 11 pieces of armor. 32 if's.
and weapons is the light one, loading 3 entries from the string array 'Weapons$' and 2 entries from the integer array 'Weapons'

so the idea was to replace the if statements with this:



what i was aiming for: to transfer the value from the two multi-dimentioned arrays (only need one from one column/each array) in to the single dimentioned 'Player$' and 'Player' arrays.

i have two arrays for every thing. one string, one integer. Weapons go Sword(0,0), Spear(1,0), Mace(2,0), ect. then the data for each one goes down from there. damage (0,0) speed (0,1) weight (0,2). you get the idea.

as far as i know every thing is set up correctly, save for this for/next loop i'm trying. it's the first time trying to make my own with out a tut to show me why mine didn't work. all i know is that putting the values to screen always returns 0

any one see any glaring flaws? or even minor ones.

thanks for let me take more of your time by reading this, and double thanks (that is worth more then a single thanks!) for any replies (even if they leave me more confused, i'm fumble my way from there.)

Anti

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 2nd Aug 2008 14:40
This is an idea, it might help.

you say you have 9 races, 12 weapons, and 11 pieces of armor.

player(9,0)=1 would mean that player 9 is race 1.

so now I add a weapon.

player(9,1)=6 would mean player 9 has weapon number 6

so now lets add some armor

player(9,2)=3 would mean player 9 has armor number 3.

now lets say you said each player can hold 4 weapons you could then say that

player(9,1) to player(9,4) will hold the numbers for 4 weapons then the armor bit would then start at player(9,5).

so if you printed it out

print player(9,0)
print player(9,1)
print player(9,2)
print player(9,3)
print player(9,4)
print player(9,5)

one the screen you would see
1
3
5
9
10
2
which converts to race 1, weapons 3=Halberd, 5=Short Sword, 9=Mace and 10=Hammer and then armor 2=sheild.

hope this help to see what to do.

Shout if its go over your head, and some else hopefully will step in and say what you should do, try.

Dark Physics makes any hot drink go cold.
Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 3rd Aug 2008 06:03
well, pretty sure i'm understanding all that; but i'm also pretty sure the setup i'v got would work.

i just need to figure out why my arrays return "0's" for stats on every thing with the for/next loop.

i'l copy the source some where and give that a go though. never know, might work better.

thanks

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 3rd Aug 2008 13:42
your set up is returning zeros as you have not put a value into any of the varables.

this
Player$(y)=Weapons$(PR,y)

puts the value of weapons$(pr,y) into player$(y), so what has been put in weapons$(pr,y)? plus I think you are using them backwards, nothing wrong with that just makes it hard to understand.
there should be something like this in your code.
weapons$(pr,1)="Pike "
weapons$(pr,2)="Billhook "
and so on.
now when you run your code it should now put the word from weapons$(pr,y) into player$(y).

did that help?

Dark Physics makes any hot drink go cold.
Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 3rd Aug 2008 13:50
wrote up the arrays in seprate source code, saved them with .Arr extensions. DIM'ed the arrays in the main source code (the one i'm having this issue with) and loaded the saved arrays into the DIM's.

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 3rd Aug 2008 14:08
Ok, so have you made a small bit of code that proves that the dim with the .arr file has been load ok.

something like :-
for i = 0 to lastone
print weapons$(i,i)
next i

plus have you looked at the .arr file in notepad just to check that is saving as you expected.

Dark Physics makes any hot drink go cold.
Anti Human
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Good ol\' West Virginia
Posted: 4th Aug 2008 22:48
Actually no i hadn't, and while doing so to test it i say one of the problems. got too use to writting HTML and using back-slash, which i did in the load arrays; even though i had saved them using forward-slash.

now when it goes to put the data to the screen it does show the race, but not race name (Elf=race, Elven=race name). so i'm still missing something.

as far as the opening in notepad, knew you could do that when you saved them as .txt but never thought to try with .arr.

have now; array races$ reads races on each line, space, then race names. array races has mostly boxes and punctuation. since their not string variables, not sure if that's right or not.

player$(0) is P_name, Player$(1) is race, Player$(2) race name, then on to weapons, armor, etc. it's getting race in to player$(1), but not race name in (2).

i'l keep toying with it, see what happens. appreciate the advice, HowDo, one step closer. thanks

Today is a good day, at least compared to tomorrow.
And every day is a good day to die, because then, there is no tomorrow

Login to post a reply

Server time is: 2024-11-24 22:28:31
Your offset time is: 2024-11-24 22:28:31