|
-
Nov 27th, 2007, 05:31 PM
#1
Thread Starter
Member
[2008] Array HELL
I'm a bit rusty with VB .NET or any programming language for that matter as I haven't touched it in over a year. Even then, I had only taken a semester of it in school.
This is the chunk of code where the file gets read into arrays and it works fine (just to help whoever will be helping me):
Code:
Dim x As Integer = 1
Dim firstcomma As Integer
Dim filenum As Integer = FreeFile()
FileOpen(filenum, "C:\lvl-xp.txt", OpenMode.Input)
Do While Not EOF(1)
tempstr = LineInput(filenum)
firstcomma = tempstr.IndexOf(",")
lvlarray(x) = tempstr.Substring(0, firstcomma)
xparray(x) = tempstr.Substring(lvlarray(x).ToString.Length + 1, tempstr.Length - lvlarray(x).ToString.Length - 1)
'MsgBox("lvl:" & lvlarray(x) & " xp:" & xparray(x))
x += 1
Loop
FileClose(1)
Here is the important part. This sub checks to see if the character has leveled up. If the totalxp is greater than the current element in the array, x should be set to the first array it finds. The PROBLEM is..it's not accurate. The first time it's called works fine.
Code:
Private Sub subnewlvl()
Dim x = 1
Do While totalxp > xparray(x)
x = x + 1
Loop
lstboxXP.Items.Add("totalxp: " & totalxp & " xparray(x): " & xparray(x) & " old lvl:" & newlvl & " New lvl:" & lvlarray(x))
newlvl = lvlarray(x)
End Sub
Here is a sample of the listbox:
The first time the loop runs, it works fine
Code:
Turned in 5 scalps for 1000 xp. Total XP:1000
totalxp: 1000 xparray(x): 1000 old lvl:1 New lvl:2
The second time is wrong. Totalxp hasn't reached 5700 so x should still be at 2. But it looks like it jumped to 3.
Code:
Turned in 5 scalps for 2000 xp. Total XP:3000
totalxp: 3000 xparray(x): 5700 old lvl:2 New lvl:3
This part is probably not important, but it's where subnewlvl() gets called.
Code:
Private Sub subscalps()
Dim pack, left, xp As Integer
left = scalps Mod 5
pack = scalps \ 5
Do While pack > 0
xp = (1000 * newlvl)
totalxp = totalxp + xp
pack = pack - 1
lstboxXP.Items.Add("Turned in 5 scalps for " & xp & " XP." & " Total XP:" & totalxp)
subnewlvl()
Loop
End Sub
And finally, here is the .txt that is read into the arrays:
Code:
1,0
2,1000
3,5700
4,15900
5,33000
6,58100
7,92600
8,137400
9,193700
10,262450
11,344700
12,441442
13,553700
14,682500
15,828700
16,993480
17,1177700
18,1382400
19,1608300
20,1857000
21,2128800
22,2425300
23,2746900
24,3095000
25,3478100
26,3875000
27,4308700
28,4772900
29,5268700
30,5797100
31,6359000
32,6956000
33,7589000
34,8257800
35,8965000
36,9711600
37,10498000
38,11325300
39,12195200
40,13108000
41,14066000
42,15069000
43,16119300
44,17217500
45,18377000
46,19602000
47,20896000
48,22262000
49,23704000
50,25227500
51,26835000
52,28531000
53,30320000
54,32208000
55,34199000
56,36298000
57,38518000
58,40844000
59,43297000
60,45882500
61,48604500
62,51471000
63,54483000
64,57650500
65,60981000
66,64483000
67,68159000
68,72020000
69,76074000
70,80320000
71,84788000
72,89459000
73,94360000
74,99485226
75,104858697
76,110489000
77,116368095
78,122525000
79,128858000
80,135683000
81,142714000
82,150048000
83,157700981
84,165691091
85,174219116
86,183314046
87,193005738
88,203324924
89,214303219
90,225973131
91,238369000
92,251523000
93,265472000
94,280253000
95,295900000
96,312452000
97,329950000
98,348435000
99,367940200
100,388515000
101,410200000
102,433039000
103,457078000
104,482360000
105,508933000
106,536847000
107,566146000
108,596884000
109,629114000
110,662878000
111,698236000
112,735240000
113,773954000
114,814418000
115,856700000
116,900856000
117,946944000
118,995025000
119,1045164000
120,1097414000
121,1151839000
122,1208532000
123,1267520000
124,1328891000
125,1394766000
126,1465353000
127,1540775000
128,1621343000
129,1707202000
130,1798604000
131,1895689000
132,1998700000
133,2107964000
134,2223594548
135,2345859740
136,2474996700
137,2611246919
138,2754856329
139,2906075326
140,3065158798
141,3232366145
142,3407961306
143,3592212780
144,3785393657
145,3999725569
146,4236116170
147,4495490778
148,4778792472
149,5086982188
150,5421038816
151,5781959301
152,6170758735
153,6588470454
154,7036146133
155,7514855881
156,8025688337
157,8569750762
158,9148169131
159,9762088230
160,10412671747
161,11101102362
162,11828581842
163,12596331130
164,13405591808
165,14323751218
166,15355130652
167,16504312961
168,17775189762
169,19172880438
170,20701812509
171,22366681987
172,24172261748
173,26123401888
174,28225030084
175,30482151954
176,32899851410
177,35483291016
178,38237712340
179,41168436309
180,44280863558
181,47580474776
182,51072831062
183,54763574263
184,58658427326
185,63115894897
186,68115894897
187,73800275488
188,80068783764
189,86983099850
190,94564821930
191,102835870903
192,111818491760
193,121535254947
194,132009057736
195,144873495079
196,160214619412
197,178119779264
198,198677624721
199,221978112873
200,248292513235
Thanks for any and all help
-
Nov 27th, 2007, 06:02 PM
#2
Re: [2008] Array HELL
It's this loop that's at fault....
Code:
Do While totalxp > xparray(x)
x = x + 1
Loop
Think about it for just as sec....
totalxp = 3000....
When it starts, x= 1....
and xparray(x) at this point is 0... since 3000 is > 0, it increments x....
so now x = 2
xparray(x) is now 1000.....
3000 is still > 1000 .... so it increments x again....
now x =3....
and xparray(x) = 5700.... and it stops the loop. With x being 3...
And xplvl(x) = 3.... so now it thinks the new level is 3....
What you need to do is after your loop, check to see if xparray(x) > totalxp... and if so, decrement x, back down (so that it becomes 2 again)....
That should solve the problem.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|