|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Battle System Help
Basically I have this battle system below, then if the winner is you (the person who initiated the battle) I have:
<cfif winner IS '#session.user_id#'> <cfquery datasource="userlogin"> update Battle set HP = '<cfoutput>#hp1#</cfoutput>' where user_id = '#session.user_id#' </cfquery> But I cannot understand how their HP comes out something like HP: 3915/50 when they should have 43/50 When the battles goes something like this.. Aeris attacks Zedicus for 12 damage (38 Hp Left) Aeris attacks Zedicus for 12 damage (26 Hp Left) Aeris attacks Zedicus for 12 damage (14 Hp Left) Zedicus attacks Aeris for 7 damage (43 Hp Left) Aeris attacks Zedicus for 12 damage (2 Hp Left) Aeris attacks Zedicus for 12 damage (0 Hp Left) Aeris defeated Zedicus ??? My code is below... <cfset counter = 0> <cfloop condition = "#HP1# GTE 1 AND #HP2# GTE 1"> <cfset counter = #counter# + 1> <cfset randomattack1 = #RandRange(1, speed1)#> <cfset randomattack2 = #RandRange(1, speed2)#> <cfif #counter# IS 1> <cfif #speed1# GTE #speed2#> <cfset hp2 = #hp2# - #hit1#> <cfset damageto2 = #hit1#> <cfif #hp2# LT 0> <cfset hp2 = 0> </cfif> <cfif #damageto2# LTE 0> User 1 hit User 2 for 0 damage.<br> <cfset #damageto2# = 0> <cfelse> <cfoutput>#Name1#</cfoutput> attacks <cfoutput>#Name2#</cfoutput> for <cfoutput>#damageto2#</cfoutput> damage (<cfoutput>#hp2#</cfoutput> Hp Left)<br> </cfif> <cfif #HP2# LTE 0> <cfoutput>#Name1#</cfoutput> defeated <cfoutput>#Name2#</cfoutput><br><br><cfbreak> </cfif> <cfelse> <cfset hp1 = #hp1# - #hit2#> <cfset damageto1 = #hit2#> <cfif #hp1# LT 0> <cfset hp1 = 0> </cfif> <cfif #damageto1# LT 0> <cfoutput>#Name2#</cfoutput> hit <cfoutput>#Name1#</cfoutput> for 0 damage.<br> <cfset #damageto1# = 0> </cfif> <cfif #damageto1# GTE 1> <cfoutput>#Name2#</cfoutput> attacks <cfoutput>#Name1#</cfoutput> for <cfoutput>#damageto1#</cfoutput> damage (<cfoutput>#hp1#</cfoutput> Hp Left)<br> </cfif> <cfif #HP1# LTE 0> <cfoutput>#Name2#</cfoutput> defeated <cfoutput>#Name1#</cfoutput><br><br><cfbreak> </cfif></cfif></cfif> <cfif randomattack1 GTE randomattack2> <cfset hp2 = #hp2# - #hit1#> <cfset damageto2 = #hit1#> <cfif #hp2# LT 0> <cfset hp2 = 0> </cfif> <cfif #damageto2# LTE 0> <cfoutput>#Name1#</cfoutput> attacks <cfoutput>#Name2#</cfoutput> for 0 damage.<br> <cfset #damageto2# = 0> <cfelse> <cfoutput>#Name1#</cfoutput> attacks <cfoutput>#Name2#</cfoutput> for <cfoutput>#damageto2#</cfoutput> damage (<cfoutput>#hp2#</cfoutput> Hp Left)<br> </cfif> <cfif #HP2# LTE 0> <cfoutput>#Name1#</cfoutput> defeated <cfoutput>#Name2#</cfoutput><br><br><cfbreak> </cfif> <cfelse> <cfset hp1 = #hp1# - #hit2#> <cfset damageto1 = #hit2#> <cfif #hp1# LT 0> <cfset hp1 = 0> </cfif> <cfif #damageto1# LT 0> <cfoutput>#Name2#</cfoutput> attacks <cfoutput>#Name1#</cfoutput> for 0 damage.<br> <cfset #damageto1# = 0> </cfif> <cfif #damageto1# GTE 1> <cfoutput>#Name2#</cfoutput> attacks <cfoutput>#Name1#</cfoutput> for <cfoutput>#damageto1#</cfoutput> damage (<cfoutput>#hp1#</cfoutput> Hp Left)<br> </cfif> <cfif #HP1# LTE 0> <cfoutput>#Name2#</cfoutput> defeated <cfoutput>#Name1#</cfoutput><br><br><cfbreak> </cfif></cfif> </cfloop> |
|
#2
|
|||
|
|||
|
Don't have time try to debug all that. But just a note that everywhere you have something like this:
<cfset hp1 = #hp1# - #hit2#> You can drop the pound signs and just do: <cfset hp1 = hp1-hit2>
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
That's some tough code to follow, because it has alot of unnecessary code in it. If you'd please clean it up some, and then repost it, I'll take another look. I'll give you some hints.
When you have a native CF tag or function, the # sign is unnecessary. <cfset hp1=hp1-hit1> See, no #. You also have quite a few <cfoutput> tags. Try putting just one at the top of the page, and another at the bottom. This should cover all the actual variable output you need. Lets make those changes, which will make you code easier to desk-walk .. then we'll talk again ![]() Dave |
|
#4
|
|||
|
|||
|
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Battle System Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|