Community
SCI Programming => SCI Community How To's & Tutorials => Topic started by: gumby on December 10, 2013, 05:03:41 PM
-
Here's a tip to save a lot of space in your scripts if you use a lot of #titles in your Print() statements. Create a procedure like this in your Main.sc:
(procedure (PrintWithTitle textRes textResIndex titleTextRes titleTextResIndex params)
Print(textRes textResIndex #title Format("%s" titleTextRes titleTextResIndex) rest params)
)
Then in your scripts, just use the new PrintWithTitle function like this:
PrintWithTitle(0 20 999 3) // 999 is a text resource where your #titles are held
// you can also use additional Print params and they will be passed through:
PrintWithTitle(0 20 999 3 #width 200 #at 25 80)
This way you can pull all the actual text for your titles out of your room scripts, saving heap space.
This technique should work for any #attribute (#text, #button, etc) where you want to move the literal text out of the script & into a text resource.
EDIT: Stop. Don't do it in the above way. It'll work, but lets address the root cause of the issue & fix the Print() routine in the template game:
Another edit: This doesn't work properly, it seemed to in my initial testing. I'm going to have to do some more debugging to figure out what is going on
In controls.sc, in the Print() procedure change the '(case #button' section:
(case #button
= hButtons[buttonCnt] (DButton:new())
(if(>= Abs(params[+ paramCnt 1]) 0 and <= Abs(params[+ paramCnt 1]) 999)
(send hButtons[buttonCnt]:
text(Format("%s" params[+ paramCnt 1] params[+ paramCnt 2]))
value(params[+ paramCnt 3])
setSize()
)
= paramCnt + paramCnt 3
)(else
(send hButtons[buttonCnt]:
text(params[++paramCnt])
value(params[++paramCnt])
setSize()
)
)
= btnsWidth (+ btnsWidth (+ (send hButtons[buttonCnt]:nsRight) 4))
++buttonCnt
)
And the '(case #title' section:
(case #title
++paramCnt
(if(>= Abs(params[paramCnt]) 0 and <= Abs(params[paramCnt]) 999)
(send hDialog:text(Format("%s" params[paramCnt] params[+ paramCnt 1])))
++paramCnt
)(else
(send hDialog:text(params[paramCnt]))
)
)
Now, you can use either technique - specify a static string or a text resource like this:
Print("Hello there" #title 999 1) // 999 is the text resource holding our title text
Print("Hello there" #title "Greetings") // the original way of specifying a title still works too
Same with buttons:
Print("Make a selection" #button 888 2) // 888 is the text resource holding our button text
Print("Make a selection" #button "OK") // the original way of specifying text for buttons still works
Of course, if you are this heap-bound, you'd have the actual text of your Print statement to be in a text resource too, so a more realistic example would be something like this:
Print(0 15 #title 999 1)
Print(0 22 #button 888 2)