Author Topic: Can you eval multiple lines?  (Read 1190 times)

/title
Could I change eval("function hasPartInString(%part, %string) { for(%i = 0; %i < getWordCount(%string); %i++) { if(%line $= getWord(%string, %i)) return true; else return false; } }");

No, that function probably doesn't work anyways, I'm doing it as an example.
to

eval("function hasPartInString(%part, %string)
{
    for(%i = 0; %i < getWordCount(%string); %i++)
    {
        if(%line $= getWord(%string, %i))
            return true;
        else
            return false;
    }
}");

?
I'm wondering this because it's easier to read functions across multiple lines.

copy it and do eval(getClipboard());

unless you mean in real code, in which case you definitely can.

you'll probably have to do like

"asdf" @/NL/SPC/watever
"butt" @/NL/SPC/watever
« Last Edit: July 04, 2014, 11:54:05 AM by otto-san »

copy it and do eval(getClipboard());

unless you mean in real code, in which case you definitely can.

you'll probably have to do like

"asdf" @/NL/SPC/watever
"butt" @/NL/SPC/watever

Thanks! So you're saying if I execute a file, and the lines do:

eval("function hasPartInString(%part, %string)
{
    for(%i = 0; %i < getWordCount(%string); %i++)
    {
        if(%line $= getWord(%string, %i))
            return true;
        else
            return false;
    }
}");

It would work? I can't test right now as I'm on my phone.

just remember that if you eval any quotation marks inside the code you're writing then you must escape it using \ otherwise the function won't work properly or throw a syntax error

eval("function hasPartInString(%part, %string)" NL
"{" NL
"    for(%i = 0; %i < getWordCount(%string); %i++)" NL
"    {" NL
"        if(%line $= getWord(%string, %i))" NL
"            return true;" NL
"        else" NL
"            return false;" NL
"    }" NL
"}");

This ought to work. Also why not just define the function directly?

Thanks! So you're saying if I execute a file, and the lines do:

eval("function hasPartInString(%part, %string)
{
    for(%i = 0; %i < getWordCount(%string); %i++)
    {
        if(%line $= getWord(%string, %i))
            return true;
        else
            return false;
    }
}");

It would work? I can't test right now as I'm on my phone.
no it wouldnt work because you're testing if an empty string equals a word

just remember that if you eval any quotation marks inside the code you're writing then you must escape it using \ otherwise the function won't work properly or throw a syntax error
Okay, thank you.
This ought to work. Also why not just define the function directly?
Thanks, Xalos.
no it wouldnt work because you're testing if an empty string equals a word
[size= 2pt]No, that function probably doesn't work anyways, I'm doing it as an example. [/size]
I'll attempt to fix it anyways though.

function hasPartInString(%string, %part)
{
    for(%i = 0; %i < getWordCount(%string); %i++)
    {
        if(getWord(%string, %i) $= %part)
            return true;
    }
    return false;
}

?
« Last Edit: July 04, 2014, 12:18:58 PM by Ninjaman 4 »

?

function hasPartInString(%string, %part)
{
    return strStr(%string, %part) != -1;
}

No need to even make that a function. Just do strPos(%string, %text) != -1)