faster performance?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
faster performance?
Hi again,
I would like to know if there is any trick to make the transition from one card to another faster.
The thing is that since I added some code on OpenCard, it takes few second more to open this card.
The code involves going over the chars of a field text in the previous card, copying some of it and making some changes.
Is there any other place where I can put that piece of code, or any line I can add to the code that makes it faster?
Thanks a lot,
Marta
I would like to know if there is any trick to make the transition from one card to another faster.
The thing is that since I added some code on OpenCard, it takes few second more to open this card.
The code involves going over the chars of a field text in the previous card, copying some of it and making some changes.
Is there any other place where I can put that piece of code, or any line I can add to the code that makes it faster?
Thanks a lot,
Marta
Re: faster performance?
Hi Marta,
could you post (some of) the script(s) involved please?
Best
Klaus
could you post (some of) the script(s) involved please?
Best
Klaus
Re: faster performance?
Sure!
Here it is:
Here it is:
Code: Select all
on preOpenCard
put empty into field "output" of card "Paraphrasing" of stack "Estratego"
repeat with i = 1 to the number of chars of field "Text2" of card "Text" of stack "Estratego"
put the backgroundcolor of char i of field "Text2" of card "Text" of stack "Estratego" into tColor
if tColor is "255,255,0" or tColor is "0,255,0" then
if tColor is "255,255,0" then -- this is yellow
put char i of field "text2" of card "Text" of stack "Estratego" after field "output" of card "Paraphrasing" of stack "Estratego"
set the textStyle of last char of field "output" of card "Paraphrasing" of stack "Estratego" to normal
end if
if tColor is "0,255,0" then -- this is green
put char i of field "text2" of card "Text" of stack "Estratego" after field "output" of card "Paraphrasing" of stack "Estratego"
set the textStyle of last char of field "output" of card "Paraphrasing" of stack "Estratego" to bold
end if
else
put return after field "output" of card "Paraphrasing" of stack "Estratego"
end if
if tColor is "253, 99, 159" then -- this is pink
put char i of field "Text2" of card "Text" of stack "Estratego" after field "Vocab" of card "Vocab" of stack "Vocab"
set the textStyle of last char of field "Vocab" of card "Vocab" of stack "Vocab" to normal
end if
end repeat
repeat with i = the number of lines of field "output" of card "Paraphrasing" of stack "Estratego" down to 1
if line i of field "output" of card "Paraphrasing" of stack "Estratego" = "" then delete line i of field "output" of card "Paraphrasing" of stack "Estratego"
end repeat
Re: faster performance?
Hi Marta,
OK, try this, maybe even "on opencard" since "lock screen" does speed up tings a lot.
Please check if this will be faster than before.
And as I mentioned above, you could also try this "on opencard".
Best
Klaus
OK, try this, maybe even "on opencard" since "lock screen" does speed up tings a lot.
Code: Select all
on preOpenCard
## Always use a "lock screen" when manipulatinmg interface elements, especially content of fields!
lock screen
put empty into field "output" of card "Paraphrasing" of stack "Estratego"
repeat with i = 1 to the number of chars of field "Text2" of card "Text" of stack "Estratego"
put the backgroundcolor of char i of field "Text2" of card "Text" of stack "Estratego" into tColor
## I always prefer "switcvh" isntead of many nested "if...then..." conditions.
switch tColor
case "255,255,0" -- this is yellow
put char i of field "text2" of card "Text" of stack "Estratego" after field "output" of card "Paraphrasing" of stack "Estratego"
set the textStyle of last char of field "output" of card "Paraphrasing" of stack "Estratego" to normal
break
case "0,255,0" -- this is green
put char i of field "text2" of card "Text" of stack "Estratego" after field "output" of card "Paraphrasing" of stack "Estratego"
set the textStyle of last char of field "output" of card "Paraphrasing" of stack "Estratego" to bold
break
default
## Neither YELLOW nor GREEN
put return after field "output" of card "Paraphrasing" of stack "Estratego"
break
end switch
if tColor = "253, 99, 159" then -- this is pink
put char i of field "Text2" of card "Text" of stack "Estratego" after field "Vocab" of card "Vocab" of stack "Vocab"
set the textStyle of last char of field "Vocab" of card "Vocab" of stack "Vocab" to normal
end if
end repeat
## In this case we can get the coplete content of the field, filter out all empty lines! and write it back into the field
## this is faster than directly manipulating the field line by line!
put field "output" of card "Paraphrasing" of stack "Estratego" into tOutput
filter tOutput without empty
put tOutput into field "output" of card "Paraphrasing" of stack "Estratego"
unlock screen
end preopencard
And as I mentioned above, you could also try this "on opencard".
Best
Klaus
Re: faster performance?
Klaus,
Putting the code on OpenCard definetely makes a difference. Thanks a lot. And your code looks much more simpler and elegant than mine, but what I don't understand is why with your code words highlighted in green are not bolded. The line of code is there, but it does not work.
I am not that familiar with switch expressions (I think I used it once for something really simple), so I dont understand why is not doing it
Thanks
Marta
Putting the code on OpenCard definetely makes a difference. Thanks a lot. And your code looks much more simpler and elegant than mine, but what I don't understand is why with your code words highlighted in green are not bolded. The line of code is there, but it does not work.
Code: Select all
case "0,255,0" -- this is green
put char i of field "text2" of card "Text" of stack "Estratego" after field "output" of card "Paraphrasing" of stack "Estratego"
set the textStyle of last char of field "output" of card "Paraphrasing" of stack "Estratego" to bold
break
Thanks
Marta
Re: faster performance?
Hi Marta,
glad it speeds up your performance!
The performance of you scripts, of course
Sorry, no idea why the last char will not get bold?
This is definitvely not a problem of the "switch" structure, since the char gets put after field "output", right?
Hint:
Since modifying contents of fields is quite time consuming, maybe you could figure out another method of working with the field?
Maybe manipulating the HTML text and then setting it back to your field? This is much faster in any case!
I mean, how do single chars get a different hilite in your app design?
Sorry, I just have no idea how your app might work
Best
Klaus
glad it speeds up your performance!
The performance of you scripts, of course

Sorry, no idea why the last char will not get bold?
This is definitvely not a problem of the "switch" structure, since the char gets put after field "output", right?
Hint:
Since modifying contents of fields is quite time consuming, maybe you could figure out another method of working with the field?
Maybe manipulating the HTML text and then setting it back to your field? This is much faster in any case!
I mean, how do single chars get a different hilite in your app design?
Sorry, I just have no idea how your app might work

Best
Klaus