StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
liuchina  
#1 Posted : Friday, October 21, 2022 12:27:36 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
Hi Rob:
I want to use DisplayText to display the count for the for loop. However, DisplayText can only display text in the for loop and cannot obtain variables. Here is my simple code. I hope I can get your help. Thank you.
Quote:
sp.Sleep(600);
var ress = Number(inputbox(" "));
for (ddi=1; ddi<=ress;ddi++){
sp.CreateTimer("test", 5, -1,
var info = new DisplayTextInfo();
info.Title = 'Test';
info.TitleAlignment = 'Center';
info.Message = ddi;//Only text can be displayed here, and variables cannot be obtained.
info.MessageAlignment = 'Left';
info.Duration = 3500;
info.Opacity = 0.7;
info.Location = 'top';
info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
info.MessageFont = new Font('Segoe UI Semibold', 12);
info.BackColor = 'black';
info.Padding = 15;
info.UsePrimaryScreen = true;
sp.DisplayText(info);
sp.DeleteTimer("test");`);

sp.Sleep(1000);
sp.SendKeys("1")
sp.Sleep(1000);
sp.SendKeys("2")
sp.Sleep(1000);
sp.SendKeys("3")
sp.Sleep(500);
sp.SendKeys("~")
}

Rob  
#2 Posted : Friday, October 21, 2022 1:03:29 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Timers execute in a thread. There are more than 1 script engine and your for loop is using the thread where the variable is defined, so it doesn't exist in the timer's thread.

However, you need to cast the variable to a string since it (.Message) accepts an object and it's creating a reference issue.

In this case, you don't need a timer (removed some stuff to simplify):
Code:
var info = new DisplayTextInfo();
info.Title = 'Test';
info.TitleAlignment = 'Center';
info.MessageAlignment = 'Left';
info.Duration = 3500;
info.Opacity = 0.7;
info.Location = 'top';
info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
info.MessageFont = new Font('Segoe UI Semibold', 12);
info.BackColor = 'black';
info.Padding = 15;
info.UsePrimaryScreen = true;

sp.Sleep(600);
var ress = 4; // Number(sp.InputBox((" "));

for (ddi=1; ddi<=ress;ddi++){
    info.Message = ""+ddi; // Cast variable to string
    sp.DisplayText(info);
    sp.Sleep(1000);
}
thanks 1 user thanked Rob for this useful post.
liuchina on 10/21/2022(UTC)
liuchina  
#3 Posted : Friday, October 21, 2022 1:37:49 AM(UTC)
liuchina

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 9/26/2018(UTC)
Posts: 73
China
Location: 北京

Thanks: 18 times
Was thanked: 1 time(s) in 1 post(s)
Your plan perfectly solved my problem, thank you very much!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.