Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Function help

  1. #1

    Post Function help

    Hey,
    I have a function that converts my money into gold, silver and copper. (code below) I was wondering if there is a way to make it so if there is 0 copper and\or silver it'd make it not show it. (IE: 200gold 300 silver 000copper make it look like this, 200gold 300 silver) Thanks for the help in advance

    function gold_format($money)
    {
    $counter=strlen($money);
    if ($counter <= 3)
    {
    $moneydone="
    $money<img src='images/Copper.png'/>";
    return $moneydone;
    }
    if ($counter <= 6)
    {
    $copper= substr($money, -3);
    $silver= substr($money, 0, -3);
    $moneydone="
    $silver<img src='images/Silver.png'/>
    $copper<img src='images/Copper.png'/>";
    return $moneydone;
    }
    else
    {
    $copper= substr($money, -3);
    $mid=($counter-6);
    $silver= substr($money, $mid, -3);
    $gold=substr($money, 0, $mid);
    $moneydone="
    $gold<img src='images/Gold.png'/>
    $silver<img src='images/Silver.png'/>
    $copper<img src='images/Copper.png'/>";
    return $moneydone;
    }
    }

  2. #2
    Use is_null
    Ruler of Zu

    FIA ISP FTW!

    MWG a discussion forum. If you do not like replies then perhaps dont start a topic.

    I no longer support Mccodes bugs, errors or security flaws either on the forum or by private message due to the lack of support by the mccodes staff for their own engine.

    If your looking for an engine get one thats supported by its staff. EzRPG and EzRPG Rework & NWE are my recommendations.

  3. #3
    Could you explain how is_null is used?

  4. #4
    You best bet for any questions about php functions is to go to PHP.net and search for the function.
    Each description usually comes with details and plenty of examples for you to figure things out on your own.
    http://us2.php.net/manual/en/function.is-null.php
    My Portfolio: Flashfire Gaming.
    All my mods for $20, exclusive resell rights $75/ea or $200 for all.
    Add your game to my list of text based games.
    Looking to advertise? Cheap rates on BestTextGames for MWG members.

  5. #5
    Well I thought just by the name of the function it would be self explanatory is null or not!
    Ruler of Zu

    FIA ISP FTW!

    MWG a discussion forum. If you do not like replies then perhaps dont start a topic.

    I no longer support Mccodes bugs, errors or security flaws either on the forum or by private message due to the lack of support by the mccodes staff for their own engine.

    If your looking for an engine get one thats supported by its staff. EzRPG and EzRPG Rework & NWE are my recommendations.

  6. #6
    is_null() how hard is it to use? Like any other function, really easy. is_null($var)...

  7. #7
    Thanks for the advice, got it to do what I needed it to do using ltrim.

  8. #8
    Kinda botch it fix isnt it?

    Sounds like you couldnt get it to work so your just removing the output.
    Ruler of Zu

    FIA ISP FTW!

    MWG a discussion forum. If you do not like replies then perhaps dont start a topic.

    I no longer support Mccodes bugs, errors or security flaws either on the forum or by private message due to the lack of support by the mccodes staff for their own engine.

    If your looking for an engine get one thats supported by its staff. EzRPG and EzRPG Rework & NWE are my recommendations.

  9. #9
    Quote Originally Posted by SomeRandomBastard View Post
    I don't even understand the damn function!

    Why do you have gold, silver and bronze all using a single field?

    I'm confused as to what is happening here and why you are splitting it 3 times.

    For simplicity, if nothing else, use 3 fields!?
    He's assuming three digits in the string, i.e. 100gold, and thus only collecting the values of them, i.e. 100.
    Flawed in some ways, but it does work if the integer value is above 100 and below 999.

    @OP:
    PHP is my wife, but JavaScript is my mistress.
    I only troll here if I have nothing better to do.

    ezRPG (latest) | ezRPG Rework (latest)

  10. #10
    Quote Originally Posted by bladewolf2010 View Post
    Hey,
    I have a function that converts my money into gold, silver and copper. (code below) I was wondering if there is a way to make it so if there is 0 copper and\or silver it'd make it not show it. (IE: 200gold 300 silver 000copper make it look like this, 200gold 300 silver) Thanks for the help in advance

    function gold_format($money)
    {
    $counter=strlen($money);
    if ($counter <= 3)
    {
    $moneydone="
    $money<img src='images/Copper.png'/>";
    return $moneydone;
    }
    if ($counter <= 6)
    {
    $copper= substr($money, -3);
    $silver= substr($money, 0, -3);
    $moneydone="
    $silver<img src='images/Silver.png'/>
    $copper<img src='images/Copper.png'/>";
    return $moneydone;
    }
    else
    {
    $copper= substr($money, -3);
    $mid=($counter-6);
    $silver= substr($money, $mid, -3);
    $gold=substr($money, 0, $mid);
    $moneydone="
    $gold<img src='images/Gold.png'/>
    $silver<img src='images/Silver.png'/>
    $copper<img src='images/Copper.png'/>";
    return $moneydone;
    }
    }
    I know what you mean. But i don't know how to code except il give you a psuedo code.

    If copper = "000" then
    copper = nothing
    else if silver = "000" then
    silver = nothing
    else if gold = "000" then
    gold = nothing
    end if

    xD ? any help there :P
    Mmomaker

Page 1 of 2 12 LastLast

Similar Threads

  1. A function...
    By CJ - Twitch in forum PHP
    Replies: 9
    Last Post: 05-31-2010, 12:14 PM
  2. need some help with this function
    By corruptcity || skalman in forum General Discussion
    Replies: 6
    Last Post: 03-27-2010, 05:59 PM
  3. Need help with a function...
    By Monkey644 in forum Modification Support
    Replies: 12
    Last Post: 01-07-2010, 08:31 AM
  4. Function help
    By War_Hero in forum General Discussion
    Replies: 9
    Last Post: 06-13-2009, 04:56 PM
  5. Function Help
    By War_Hero in forum General Discussion
    Replies: 2
    Last Post: 08-06-2008, 01:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •