Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Call to undefined method  (Read 6649 times)

0 Members and 1 Guest are viewing this topic.

theflash

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Call to undefined method
« on: December 04, 2009, 11:27:33 AM »

Okay, I hope the solution to this won't be as embarassingly simple as last time.

When I implement something along the lines of

var test = "Hello. I am a Test.";
var dummy = test.Split(".");

I get a "Call to undefined method 'Split'. Ignored."

My search through these forums suggested, that this would happen, if test was [null] or undefined. But it's not. A "Game.Msg(test)" works fine.
Logged

Spellbreaker

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Gender: Male
  • Posts: 376
    • View Profile
    • Apeiron Studios
Re: Call to undefined method
« Reply #1 on: December 04, 2009, 12:31:54 PM »

Hi.

var myStr = new String("Hello. World");
var splitArr = myStr.Split(".");

That should work :) I gues the missing "new String" is the problem on your code.
Logged

theflash

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Call to undefined method
« Reply #2 on: December 04, 2009, 01:27:50 PM »

Nope. That didn't do it.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Call to undefined method
« Reply #3 on: December 04, 2009, 03:03:00 PM »

It should. How does your code look now?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

theflash

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Call to undefined method
« Reply #4 on: December 04, 2009, 03:49:55 PM »

Okay, no idea why, but I've just created a new script file and it works now. Don't know where the difference is/was, but I'm happy for now.
Logged

Ennio

  • Lurker
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 40
    • View Profile
Re: Call to undefined method
« Reply #5 on: January 15, 2012, 05:38:29 PM »

I have to resume this post because i found the same problem.
I have an editor where player can write some text, and i want to split it in token using space character as separator

this is my code

Code: WME Script
  1. var solution = new String(text);
  2. solution = solution.ToLowerCase();
  3. var solutionArray = solution.Split(" ");

I get a "Call to undefined method 'Split'" error.
Any idea?
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Call to undefined method
« Reply #6 on: January 16, 2012, 04:51:07 PM »

is "text" by any chance null?
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Jose

  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Posts: 134
    • View Profile
Re: Call to undefined method
« Reply #7 on: January 16, 2012, 06:43:31 PM »

Hi Ennio,

I think the problem is that the method ToLowerCase isn't returning a String (or something similar). If you change

Code: WME Script
  1. solution = solution.ToLowerCase();
  2.  

for

Code: WME Script
  1. solution = new String(solution.ToLowerCase());
  2.  

this should do the trick, I hope.
« Last Edit: January 16, 2012, 07:38:39 PM by Jose »
Logged

Ennio

  • Lurker
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 40
    • View Profile
Re: Call to undefined method
« Reply #8 on: January 17, 2012, 01:03:41 PM »

All right! ToLowerCase doesn't return a String Object, so now it works perfectly!
Logged
 

Page created in 0.11 seconds with 21 queries.