Jump to content


Photo

32 to 3 and 2?


  • Please log in to reply
9 replies to this topic

#1 Detail

Detail

    King Detail

  • Hosted
  • 7,767 posts
  • Location:Dayonic
  • Projects:Dayvi.com
  •  Blu Spy

Posted 02 November 2005 - 03:39 PM

I'm improving the graphics on my RPG. Instead of having some text say "You slash the Wolf with your TinSword, doing 6 damage." i want it to show an image of of a slash mark and the number 6. Which i can do easy.

Problem comes when the numbers reach double figures. I'm not going to make 9999 images, one for each ammout of damage that can be done. Instead i just want to make 0-9 then then put them next to each other, so that i have my 1.gif next to 3.gif to make it look like 13.

What do i put in php to make this happen?

#2 DCoder

DCoder

    One of the Few

  • Members
  • 331 posts
  • Location:Lithuania, Central Europe
  •  Old Grumpy Bastard

Posted 02 November 2005 - 03:56 PM

For two-digit numbers, just use floor($value / 10) and $value % 10.

For longer numbers, one way off the top of my head would be
<?php
$value = 135125; // $value is your number
$value = (string)$value;
for ($i = 0; $i < strlen($value); $i++)
 print $value[$i] . '<br />'; 
?>

Ares - How do you want to improve YR today?
What's stopping you from migrating to Ares? We can't implement it unless you tell us!

ModEnc - C&C Modding Encyclopedia | Modders' Quote Database | Yet Another C&C Modding Forum

#3 Guest_ImmoMan_*

Guest_ImmoMan_*
  • Guests

Posted 02 November 2005 - 05:16 PM

Strings in PHP are strictly not arrays, so you'd use curly braces for the character index:

$value{$i}

See here for more info:
http://www.php.net/types.string

Edited by ImmoMan, 02 November 2005 - 05:18 PM.


#4 Detail

Detail

    King Detail

  • Hosted
  • 7,767 posts
  • Location:Dayonic
  • Projects:Dayvi.com
  •  Blu Spy

Posted 02 November 2005 - 05:25 PM

DCoder, Thanks :)

<?php
$value = 135125;
$value = (string)$value;
echo ("<img src=".$value{0}.".gif>");
echo ("<img src=".$value{1}.".gif>");
echo ("<img src=".$value{2}.".gif>");
echo ("<img src=".$value{3}.".gif>");
echo ("<img src=".$value{4}.".gif>");
?>

Now i have everything i need to make my interface look like FF :p


Immo, Both [ and { work.

#5 DCoder

DCoder

    One of the Few

  • Members
  • 331 posts
  • Location:Lithuania, Central Europe
  •  Old Grumpy Bastard

Posted 02 November 2005 - 05:26 PM

[] works for me (PHP 5.0.2).
Ares - How do you want to improve YR today?
What's stopping you from migrating to Ares? We can't implement it unless you tell us!

ModEnc - C&C Modding Encyclopedia | Modders' Quote Database | Yet Another C&C Modding Forum

#6 Guest_ImmoMan_*

Guest_ImmoMan_*
  • Guests

Posted 02 November 2005 - 06:08 PM

I know [ ] still works for strings, but it's deprecated since PHP 4 according to the PHP site. So it might not be there the next time you need it. :p

#7 DCoder

DCoder

    One of the Few

  • Members
  • 331 posts
  • Location:Lithuania, Central Europe
  •  Old Grumpy Bastard

Posted 02 November 2005 - 06:12 PM

Thanks for letting me know, then. :p
Ares - How do you want to improve YR today?
What's stopping you from migrating to Ares? We can't implement it unless you tell us!

ModEnc - C&C Modding Encyclopedia | Modders' Quote Database | Yet Another C&C Modding Forum

#8 Blodo

Blodo

    The one who disagrees

  • Project Team
  • 3,002 posts
  • Location:Eastern Europe
  • Projects:siteMeister, Mental Omega
  •  The wise guy

Posted 02 November 2005 - 06:26 PM

DCoder, Thanks  :)

<?php
$value = 135125;
$value = (string)$value;
echo ("<img src=".$value{0}.".gif>");
echo ("<img src=".$value{1}.".gif>");
echo ("<img src=".$value{2}.".gif>");
echo ("<img src=".$value{3}.".gif>");
echo ("<img src=".$value{4}.".gif>");
?>

Now i have everything i need to make my interface look like FF  :p


Immo, Both [ and { work.

<{POST_SNAPBACK}>

I'd use gd library.

http://www.php.net/gd

Edited by Blodo, 02 November 2005 - 06:28 PM.

ARGUMENT FROM CREATION, a.k.a. ARGUMENT FROM PERSONAL INCREDULITY (I)
(1) If evolution is false, then creationism is true, and therefore God exists.
(2) Evolution can't be true, since I lack the mental capacity to understand it; moreover, to accept its truth would cause me to be uncomfortable.
(3) Therefore, God exists.


#9 Guest_ImmoMan_*

Guest_ImmoMan_*
  • Guests

Posted 02 November 2005 - 06:28 PM

Why? GD is a lot harder to learn, is nonstandard, and this works too doesn't it? :p

#10 Blodo

Blodo

    The one who disagrees

  • Project Team
  • 3,002 posts
  • Location:Eastern Europe
  • Projects:siteMeister, Mental Omega
  •  The wise guy

Posted 02 November 2005 - 06:30 PM

GD aint as hard as you'd think, more and more people use it by the day since its just really really useful. All you have to do is know the functions - thats what php is all about.

ARGUMENT FROM CREATION, a.k.a. ARGUMENT FROM PERSONAL INCREDULITY (I)
(1) If evolution is false, then creationism is true, and therefore God exists.
(2) Evolution can't be true, since I lack the mental capacity to understand it; moreover, to accept its truth would cause me to be uncomfortable.
(3) Therefore, God exists.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users