1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Remove Lore

Discussion in 'Development' started by Junkdude, Jul 31, 2017.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Hi I wanted to know how i could remove a lore line. here is my code, it works I just dont know how to remove the line.
    PHP:
    foreach($lore as $line) {
                    if(
    stripos($line$this->getCEName($id))) {
                        
                        
    var_dump("it does");
                        
    //var_dump($line[]);
                        
                    
    }
                    return 
    true;
                }
     
  2. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    Get the index, then unset it, ultimately apply the new lore.
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    like this?
    PHP:
    unset($line);
     
    $item->setLore($lore);
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Well, you could try it for yourself...
    Or you could think it through logically:

    how can you use a foreach function to get the key along with the array data?
    PHP:
    foreach($arr as $key => $data) {

    }

    After your check on the data returns true that it is what you want to delete, how do you use the array key to delete the data from the array?
    PHP:
    foreach($arr as $key => $data) {
        if(
    $yourCheckHere) {
            unset(
    $arr[$key]);
            
    $item->setLore($arr);
        }
    }

    Now you get to adjust your code to what you learned ;)
     
    Last edited: Aug 1, 2017
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Thank you sir
     
  6. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    You could find the index with array search.
    $lores = $item->getLore();
    $index = array_search("Some Lore", $lores);
    unset($lores[$index]);
    $item->setLore($lores);

    You can use foreach loop also as Jason said
     
    Teamblocket and jasonwynn10 like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.