View Single Post
  #1  
Old 08-05-2013, 09:11 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
Function not returning a value

Hello,

I have made a pretty neat function that replaces a value from inside of a string to another value. This would have worked great, but for some reason, it's not returning the correct value. I have echoed the value before it is returned, and that value is correct, but it will not work for the return.

PHP Code:
function onCreated() {
    echo(
replaceVal("Testing-123-456","-""huh"));
}

function 
replaceVal(temp.stringtemp.oldvaltemp.newval) {
  
temp.xa 0;
  for(
temp.val 0temp.val temp.string.length(); temp.val++) {
    
temp.arr null;
    
temp.arr.add(temp.string.substring(temp.valtemp.oldval.length()));
    for(
temp.val2 0temp.val2 temp.arr.size(); temp.val2++) {
      if(
temp.arr[temp.val2] == temp.oldval) {
        
temp.newstring temp.string.substring(0temp.val) @ temp.newval temp.string.substring(temp.val temp.oldval.length());
        
temp.xa++;
      }
    }
  }
  if(
temp.xa 1) {
    
replaceVal(temp.newstringtemp.oldvaltemp.newval);
  }
  else {
    echo(
temp.newstring);  //Correctly echoes Testinghuh123huh456
    
return temp.newstring;  //Does not return Testinghuh123huh456
  
}

This -should- have returned Testinghuh123huh456. It echoes correctly as I said in a comment in my script too.

Thanks in advance for helping me
Reply With Quote