Computer Science Canada Reseting A Variable |
Author: | Mr. T [ Mon Mar 21, 2005 11:33 pm ] | ||
Post subject: | Reseting A Variable | ||
I have gone through many possible combinations but i dont know why the timeBonus ISNT reseting??
any suggestions of what i shuold put in my reset variable section? |
Author: | Naveg [ Mon Mar 21, 2005 11:36 pm ] |
Post subject: | |
all that commenting makes it very hard to read otherwise, it looks like bonus is always 60, which would reset timeBonus everytime you used it |
Author: | Mr. T [ Mon Mar 21, 2005 11:44 pm ] |
Post subject: | |
thats exactly what isnt happening... cuz for some reason timeBonus just seems to continue from where it left off at the end of each level im confused |
Author: | StarGateSG-1 [ Mon Mar 21, 2005 11:53 pm ] |
Post subject: | |
ummm. you need to reset manually which you aren't doing. |
Author: | Mr. T [ Mon Mar 21, 2005 11:54 pm ] |
Post subject: | |
so what exactly should i put into my reset variable section then??? i tried a few combinations, and none worked. |
Author: | zylum [ Tue Mar 22, 2005 12:09 am ] |
Post subject: | |
what do you mean reseting? what value do you want it to be? |
Author: | Mr. T [ Tue Mar 22, 2005 12:11 am ] | ||
Post subject: | |||
i want the same scoring system to apply to each level 1. var bonus:int:=60000 div 1000 2. var timeBonus:int :=bonus-Time.Elapsed div 1000 3. score:=score+timeBonus .... maybe if i post my whole code, it will be easier to see what i mean.
|
Author: | zylum [ Tue Mar 22, 2005 12:14 am ] | ||
Post subject: | |||
the reason youre time bonus stays at 60 is because youre program runs too fast. you need some body code before you give timeBonus a value because such little time goes by that there really isnt a change in time (a few milliseconds)
|
Author: | Mr. T [ Tue Mar 22, 2005 12:18 am ] |
Post subject: | |
the problem seems to lie in the timeBonus notice how each level it progressively decreases i dont want that ---- it should only fluctuate based on the amount of time spent in a level |
Author: | zylum [ Tue Mar 22, 2005 12:28 am ] | ||
Post subject: | |||
forget my post above. i didnt understand the problem until you posted the code. what you have to do is keep track of the time just before the level starts. then for the total time spent in that level, you just subtract the current time by the time at the beginning of the level... look how i used the STARTTIME variable in your code:
|
Author: | Mr. T [ Tue Mar 22, 2005 12:37 am ] | ||
Post subject: | |||
thx it works great...but just for my own knowledge can u explain this line to me
|
Author: | zylum [ Tue Mar 22, 2005 12:49 am ] | ||
Post subject: | |||
i thought i did explaing it... STARTTIME is the time when the level starts. to find the total time spent in that one level, you subtract the start time from the current time (Time.Elapsed - STARTTIME). After giving time bonus a new value, you set the value of STARTTIME to the current time because you are starting a new level... oh wait thats a mistake, it should be reset after you press the enter key to start the new level, otherwise time is being wasted while waiting for keyboard input... you should have this:
|
Author: | StarGateSG-1 [ Tue Mar 22, 2005 12:23 pm ] |
Post subject: | |
I guess I don't need to respond except to say that zylum has it right on. You had all the variable reseting and never chnaged the level time back so it just kept starting were it left off. |
Author: | Mr. T [ Tue Mar 22, 2005 9:55 pm ] |
Post subject: | |
kk thanks |
Author: | Mr. T [ Tue Mar 22, 2005 11:59 pm ] |
Post subject: | |
with the way i set up my code... is it possible to effectively use a flexible array to make the snake grow? or would i have to change stuff? |
Author: | MysticVegeta [ Fri Mar 25, 2005 8:55 am ] |
Post subject: | |
yes i believe you can use a flexible array to make the snake grow, there is a great tut with examples by Cervantes in the tut section. Just check it out. |