Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.