Computer Science Canada need help with health code |
Author: | ut2004 [ Thu Jun 12, 2008 2:15 pm ] |
Post subject: | need help with health code |
When health = 0 I want it so that the program doesn't end but it disallows the user to move the character after hes dead. |
Author: | jeffgreco13 [ Thu Jun 12, 2008 2:29 pm ] |
Post subject: | Re: need help with health code |
it is really impossible to help when all were given is "health = 0"... and what exactly do u mean? you want the guy or w/e to not be able to move but other things are still going on? the user can still interact with the progrm? |
Author: | ut2004 [ Thu Jun 12, 2008 3:06 pm ] |
Post subject: | Re: need help with health code |
when my health intetger becomes 0 i want the guy to not be able to move but things are still going on |
Author: | DemonWasp [ Thu Jun 12, 2008 3:39 pm ] |
Post subject: | RE:need help with health code |
You're really going to have to explain more, and probably post a lot more of your code. We have no idea how you've implemented input handling / character movement, so we can't offer advice without knowing more. Post your main game loop or similar structure here so we can understand what it is you're trying to do. Make sure you use the syntax tags when you do so: [ syntax="turing ] code goes here... [ / syntax ] without spaces. |
Author: | Tony [ Thu Jun 12, 2008 3:46 pm ] |
Post subject: | RE:need help with health code |
exit the move procedure unless health > 0. |
Author: | ut2004 [ Thu Jun 12, 2008 4:04 pm ] | ||
Post subject: | Re: need help with health code | ||
|
Author: | DemonWasp [ Thu Jun 12, 2008 8:05 pm ] | ||
Post subject: | RE:need help with health code | ||
Assuming "monk" is the player, then what you want to do is in the block at the bottom. You already have the code to detect "if health <= 0 then". All you need to do is exit the loop after you've done the picture-drawing and the "Wizard Wins" font-writing. You can modify the code to be as follows:
The "exit" line tells the program to leave your loop-end loop structure when it gets to that part. After your "end loop", you should have the cleanup / game-over code. |
Author: | riveryu [ Thu Jun 12, 2008 8:41 pm ] |
Post subject: | RE:need help with health code |
I dont think theres too much point reseting variables if you are going to exit right after, but then again I dont know what your planning after it. |
Author: | Hendo [ Sun Jun 15, 2008 5:17 pm ] |
Post subject: | RE:need help with health code |
or simply create a boolean variable and only move him if its true and when he dies set it to false |
Author: | TheGuardian001 [ Sun Jun 15, 2008 7:57 pm ] | ||
Post subject: | Re: need help with health code | ||
or you could just do
that way it only does the move condition if they have at least 1 health left... game keeps going but player cant move. |
Author: | riveryu [ Sun Jun 15, 2008 8:52 pm ] | ||
Post subject: | Re: need help with health code | ||
@TheGuardian001, I dont know but wouldnt the computer do less calculation if it just checks if health > 0 once, stores it in a boolean var and other ifs will just compare with that var. e.g
|
Author: | DemonWasp [ Mon Jun 16, 2008 8:10 am ] |
Post subject: | RE:need help with health code |
Not necessarily, riveryu. It really depends on the execution environment, compiler / interpreter, and so forth. Depending on compiler, comparing (health > 0) may do something like: LOAD health JUMP-LESS-EQUAL health, 0, END-IF ... if-code ... While something like assigning alive := true, then comparing to it may do the following: JUMP-GREATER health, 0, END-IF STORE health, 0 ... intervening code ... LOAD alive JUMP-EQUAL alive, 0, END-IF So if we assume some fairly optimal code, then memorizing a single comparison isn't necessarily a good plan. You'd be correct if it was calling any methods (method-call overhead), or was doing any actual arithmetic, but a simple compare probably doesn't need it, speed-wise. That said, using "alive" instead of "health > 0" may be more readable, and is probably easier to change later, if the conditions on "alive" ever change (maybe the player has some equipment that lets them stay alive to -10 HP?). Oh, and it's in Turing, so it's fairly unclear what's *actually* faster. Truth is, if you want it to execute quickly, you aren't writing Turing in the first place. The only language I've ever heard of being slower than Turing is Javascript, and then only when the implementation is bad ![]() |