ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 14th, 2004, 08:40 AM
charmed0rz charmed0rz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 142 charmed0rz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 49 m 31 sec
Reputation Power: 5
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>

Reply With Quote
  #2  
Old December 14th, 2004, 10:21 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
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

Reply With Quote
  #3  
Old December 14th, 2004, 10:39 AM
VelvettFogg VelvettFogg is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 34 VelvettFogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 46 sec
Reputation Power: 4
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

Reply With Quote
  #4  
Old December 14th, 2004, 11:15 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Battle System Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway