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: Problems with substrings  (Read 3359 times)

0 Members and 1 Guest are viewing this topic.

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Problems with substrings
« on: October 02, 2006, 02:19:39 AM »

Hi everyone,

I have some problems with substrings at the moment.

If I use something like
Code: [Select]
var Number=new String("1234");

var Sub=Number.Substr(2,1);
I get 3 as the result, which is right.

But if I use
Code: [Select]
var Number=new String("1234");
var Temp=5678

Number=ToString(Temp);

var Sub=Number.Substr(2,1);
I get "null" as the result.

Is there something wrong with converted string?

Thanks
Mac
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Problems with substrings
« Reply #1 on: October 02, 2006, 07:35:06 AM »

You will need to do this:

Code: [Select]
Number=new String(ToString(Temp));
var Sub=Number.Substr(2,1);

ToString() only converts the value from number to string, not to string *object*. That's the way strings work in WME, the engine differentiates between plain string values and string objects (mainly for performance reasons).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Problems with substrings
« Reply #2 on: October 02, 2006, 11:38:02 AM »

Yes , I see ...

I have written myself a function to let the actor read a number:
Code: [Select]
function SayNumber(Number)
{
  var Zahl;
  Zahl[0]="null";
  Zahl[1]="eins";
  Zahl[2]="zwei";
  Zahl[3]="drei";
  Zahl[4]="vier";
  Zahl[5]="fünf";
  Zahl[6]="sechs";
  Zahl[7]="sieben";
  Zahl[8]="acht";
  Zahl[9]="neun";

  var GZahl;
  GZahl[0]="Null";
  GZahl[1]="Eins";
  GZahl[2]="Zwei";
  GZahl[3]="Drei";
  GZahl[4]="Vier";
  GZahl[5]="Fünf";
  GZahl[6]="Sechs";
  GZahl[7]="Sieben";
  GZahl[8]="Acht";
  GZahl[9]="Neun";

  var Number2=new String("1234");
  Number2=ToString(Number);

  if(Number2.Length>1) {
     for(var Pos=0; Pos<Number2.Length-1; Pos=Pos+1) {
       if(Pos==0) {
          actor.Talk(GZahl[Number2.Substr(Pos,1)]+" ...","ui\looky\zahlen\"+Number2.Substr(Pos,1)+".ogg");
       } else {
          actor.Talk("... "+Zahl[Number2.Substr(Pos,1)]+" ...","ui\looky\zahlen\"+Number2.Substr(Pos,1)+".ogg");
       }
     }
  }
  actor.Talk("... "+Zahl[Number2.Substr(Number2.Length-1,1)]+".","ui\looky\zahlen_ende\"+Number2.Substr(Number2.Length-1,1)+".ogg");
}

I wanted to give the function an integer number as the parameter. I would have changed the code so that my number is stored in a real string object but the number is randomly generated and so I have to use integers instead. Is there no way to let my actor "speak" such a number with the code above?

Thanks
Mac
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Problems with substrings
« Reply #3 on: October 02, 2006, 11:41:52 AM »

As I said, if you replace

  Number2=ToString(Number);

with

  Number2=new String(ToString(Number));

it should work (I hope :))
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mac

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 136
    • View Profile
    • Homepage
Re: Problems with substrings
« Reply #4 on: October 02, 2006, 11:58:46 AM »

Uh, em,

... sorry, I wasn't able to open my eyes wide enough to see that  ;D...

but now everything is working (not only my eyes but the code).

Thanks a lot
Mac

*banging his head on the desktop for reformation*  ::rock
Logged
 

Page created in 0.043 seconds with 19 queries.