need help with assigning id's in code

im sure its simple code but im stuck...need to give a target to attack

Page 1 of 1

3 Replies - 406 Views - Last Post: 15 May 2010 - 03:42 AM Rate Topic: -----

#1 bloody_wings  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-May 10

need help with assigning id's in code

Posted 14 May 2010 - 02:16 AM

Hi, im pretty new at php and ive just started coding a fighting game.
Seem to be running into brick walls endlessly.

Im stuck on a bit that im sure is basic.
I want to give each of the 'fighters' below a target from the avalible fighters that isnt themselves.

//EXAMPLE $fighters  
		$fighters[0]='satan';
		$fighters[1]='daegon';
		$fighters[2]='krell';




foreach ($fighters as $id => $name) {

$fighter=mysql_query("SELECT*FROM`units`WHERE`u_nam`= '$name'");
$fighter=mysql_fetch_array($fighter);

$fighter_stats[$name]['id']=$fighter['u_id'];
$fighter_stats[$name]['name']=$fighter['u_nam'];
$fighter_stats[$name]['ene_cur']=$fighter['ene_cur'];
$fighter_stats[$name]['ene_max']=$fighter['ene_max'];
$fighter_stats[$name]['qua_cur']=$fighter['qua_cur'];
$fighter_stats[$name]['qua_max']=$fighter['qua_max'];
$fighter_stats[$name]['pas_cur']=$fighter['pas_cur'];
$fighter_stats[$name]['pas_max']=$fighter['pas_max'];
$fighter_stats[$name]['con_cur']=$fighter['con_cur'];
$fighter_stats[$name]['con_max']=$fighter['con_max'];
$fighter_stats[$name]['kil_cur']=$fighter['kil_cur'];
$fighter_stats[$name]['kil_max']=$fighter['kil_max'];



Is This A Good Question/Topic? 0
  • +

Replies To: need help with assigning id's in code

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,441
  • Joined: 23-August 08

Re: need help with assigning id's in code

Posted 14 May 2010 - 04:51 AM

$fighter=mysql_query("SELECT*FROM`units`WHERE`u_nam`= '$name'");
$fighter=mysql_fetch_array($fighter);

Why the heck are you using the same variable for the return from the query and to contain each individual result? That's going to screw you up.
Was This Post Helpful? 0
  • +
  • -

#3 bloody_wings  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-May 10

Re: need help with assigning id's in code

Posted 14 May 2010 - 05:46 AM

View PostJackOfAllTrades, on 14 May 2010 - 03:51 AM, said:

$fighter=mysql_query("SELECT*FROM`units`WHERE`u_nam`= '$name'");
$fighter=mysql_fetch_array($fighter);

Why the heck are you using the same variable for the return from the query and to contain each individual result? That's going to screw you up.



Really? Thanks i didnt know that, ill change it. :smile2:
Still lost with the choosing target tho, any advice would be great.
Was This Post Helpful? 0
  • +
  • -

#4 bloody_wings  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-May 10

Re: need help with assigning id's in code

Posted 15 May 2010 - 03:42 AM

....Still real messy.
Ive put down:

function target_list($own) {
      return (substr($own,$fighter_stats[$id]['id'])=="$fighter_stats[$id]['id']");
    }
	$target=array($fighter_stats);
    $avalible=array_filter($fighter_stats[$id],"target_list");
    $targeted=array_rand($avalible,1);
	
}



But thats not even close, any suggestions would be sweet.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1