Author Topic: Struggling with String operations in Squirrel...  (Read 2088 times)

Arcadefan1

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Struggling with String operations in Squirrel...
« 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!

mahuti

  • Administrator
  • Sr. Member
  • *****
  • Posts: 252
    • View Profile
    • Github Repositories
Re: Struggling with String operations in Squirrel...
« Reply #1 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");
« Last Edit: January 24, 2021, 11:34:55 AM by mahuti »