Jump to content


Photo

pffff more problems


  • Please log in to reply
10 replies to this topic

#1 tomasart

tomasart

    GMC Member

  • GMC Member
  • 199 posts

Posted 06 April 2012 - 11:08 AM

Hi all.

The split string don't work in HTML5. Works on windows only for me.

Example:

conta_letras = split_string(numero_array_letras, ',','array_letras');

for (i=0; i<conta_letras; i+=1) {
show_message("content:"+array_letras[i]);
}


the problem is that the variable "array_letras" is always 0. I have try other explode scripts from the community but always the same problem. I thing he recognice the variable array_letras as a string.

Please can anyone help me with alternative way to split a string?
  • 0

#2 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 1502 posts
  • Version:GM:Studio

Posted 06 April 2012 - 12:16 PM

There isn't a split_string() function in GML, where are you getting that from?

Do you have an extension perhaps?
  • 0

#3 tomasart

tomasart

    GMC Member

  • GMC Member
  • 199 posts

Posted 06 April 2012 - 02:42 PM

There isn't a split_string() function in GML, where are you getting that from?

Do you have an extension perhaps?


sorry tou are right.

// Usage: split_string(string_to_split, delimiter, array_name)
// This script takes a string such as "123|456|dog|cat|3.14159" and splits
// it up into an array.  The function returns the number of fields.

var i, p, ch, item, len, str, delimiter, array_name;

str = argument0;
delimiter = argument1;
array_name = argument2;

// If no second argument was passed, use the default delimiter (pipe):
if is_real(delimiter) { delimiter = "|" }

// If no third argument was passed, use the default destination array (split_values):
if is_real(array_name) { array_name = "split_values" }

i = 0;
item = "";
str += delimiter;
len = string_length(str);

for (p=1; p<=len; p+=1) {
    ch = string_char_at(str, p);
    if (ch == delimiter) {
        variable_local_array_set(array_name, i, item);
        item = "";
        i += 1;
    }
    else {
        item += ch;
    }
}

return i;

  • 0

#4 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 1415 posts
  • Version:Unknown

Posted 06 April 2012 - 03:02 PM

HTML5 does not support variable_local_array_set (and will NOT because of obfuscation, I suggest you use a ds_map to manage this).
  • 0

#5 Destron

Destron

    GMC Member

  • GMC Member
  • 919 posts
  • Version:GM:HTML5

Posted 09 April 2012 - 03:38 AM

This will put it in to an array for you and does work in HTML5

Usage: string_explode(string, delimiter)

var c, i, j, k, s;
s = "";
i = 0;
k = string_length(argument0);

for (j = 1; j <= k; j += 1)
{
    c = string_char_at(argument0, j);
    if (c == argument1)
    {
        ARRAYNAME[i] = s;
        s = "";
        i += 1;
        continue;
    }
    s = s + c;
}
if (s != "")
 ARRAYNAME[i] = s;

  • 0

#6 tomasart

tomasart

    GMC Member

  • GMC Member
  • 199 posts

Posted 09 April 2012 - 01:25 PM

This will put it in to an array for you and does work in HTML5

Usage: string_explode(string, delimiter)

var c, i, j, k, s;
s = "";
i = 0;
k = string_length(argument0);

for (j = 1; j <= k; j += 1)
{
    c = string_char_at(argument0, j);
    if (c == argument1)
    {
        ARRAYNAME[i] = s;
        s = "";
        i += 1;
        continue;
    }
    s = s + c;
}
if (s != "")
 ARRAYNAME[i] = s;


GREAT, thanks.
  • 0

#7 D1g1talAli3n

D1g1talAli3n

    BoyGenius

  • New Member
  • 963 posts
  • Version:GM8

Posted 09 April 2012 - 01:29 PM


This will put it in to an array for you and does work in HTML5

Usage: string_explode(string, delimiter)

var c, i, j, k, s;
s = "";
i = 0;
k = string_length(argument0);

for (j = 1; j <= k; j += 1)
{
    c = string_char_at(argument0, j);
    if (c == argument1)
    {
        ARRAYNAME[i] = s;
        s = "";
        i += 1;
        continue;
    }
    s = s + c;
}
if (s != "")
 ARRAYNAME[i] = s;


GREAT, thanks.

I'm pretty sure that's not going to work.
  • 0

#8 Destron

Destron

    GMC Member

  • GMC Member
  • 919 posts
  • Version:GM:HTML5

Posted 10 April 2012 - 03:40 AM

Pretty sure its ripped right out of 3 different games that I am using it in in which it does work
  • 0

#9 D1g1talAli3n

D1g1talAli3n

    BoyGenius

  • New Member
  • 963 posts
  • Version:GM8

Posted 10 April 2012 - 05:07 AM

Pretty sure its ripped right out of 3 different games that I am using it in in which it does work

Yes but in your code the array name is static. You cannot change the name of the array in realtime. The whole point of using variable_local_array_set() is to use the name of the array given in the argument of the script. It serves the same purpose, however, does the same thing, which I will agree on.
  • 0

#10 Destron

Destron

    GMC Member

  • GMC Member
  • 919 posts
  • Version:GM:HTML5

Posted 10 April 2012 - 05:22 AM

I did not intend to imply it would fully replace variable_local_array_set(), but it will explode a delimited string which is what he wanted.
  • 0

#11 tomasart

tomasart

    GMC Member

  • GMC Member
  • 199 posts

Posted 10 April 2012 - 12:45 PM

the example works for my porpuose. Thanks Destron.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users