Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: Arcadefan1 on March 20, 2017, 12:13:20 PM

Title: Struggling with String operations in Squirrel...
Post by: Arcadefan1 on March 20, 2017, 12:13:20 PM
Hey guys,
I am new to attract mode and I try to get my head around modifying a theme.


First question:
I get a string back from calling a function. Like this...

Local scroller = "[!get_history]";

The string shows ok on screen. It contains the text from history.dat. But if I try something like

Local length = scroller.len();

I always get 14. And when I print the string to console it says  "[!get_history]"
It seems like it behaves similar to a magic token.
How do I convert such a string to a real string with real content?


Second question:
How do I remove all line feeds (/n) from a string?

Any help is appreciated!
Title: Re: Struggling with String operations in Squirrel...
Post by: mahuti on March 20, 2017, 03:39:56 PM
I had the same problem. I looked it up.... and basically you're right. Those are late parsed, you have to use a callback.

Code: [Select]
Local scroller = "[!get_history]";
local scroller_length = 0
function history_text_length( tick_time )
{     
    scroller_length =  scroller.len()
    return false
}
fe.add_ticks_callback("history_text_length");