How to place a text slice connected to a timer.

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Seamus Moore
Slime
Posts: 19
Joined: Mon Mar 16, 2020 9:39 pm
Location: Seamus Moore's House

How to place a text slice connected to a timer.

Post by Seamus Moore »

I made a timer that counts down for two minutes. I want a text slice to visually display how much time is left on the screen. But I have no idea how to use slices, I find the tutorial on the wiki to be completely incomprehensible. Can someone simply tell me what the script for making a simple single text slice, connected to a timer would be like?
dQw4w9WgXcQ
User avatar
Rue
Slime Knight
Posts: 118
Joined: Sun Dec 09, 2007 4:01 am
Location: Bellevue, WA
Contact:

Post by Rue »

Alright, so you first gotta have a text slice to work with and a way to refer to it.

You do that with something like:

variable (myTextSlice) # Sets up a new variable called myTextSlice
myTextSlice:=create text # Makes a new text slice, returns the "handle", and since we're setting myTextSlice to whatever "create text" returns, myTextSlice now equals the "handle" is.

Now myTextSlice is the "handle" of the text slice you just created, meaning you can manipulate it.

We can do a few things here.

$1="Banana"
set slice text(myTextSlice, 1)

This sets the "text" attribute of your slice to whatever string 1 is, which is "Banana". That means it'll show "Banana" wherever the slice is now.

set slice x(myTextSlice,0)
set slice y(myTextSlice,0)

This sets the x and y coordinates of your slice to 0,0 (relative to camera, by default). You should see "Banana" on the top left of the screen.

When you're done, you'll want to use:
free slice (myTextSlice)

This will get rid of the slice. Not "hide" it, but actually get rid of it. Important to clean up, otherwise you'll end up with a bunch of unnecessary objects layered all over you screen, or in memory.

That's a real simple tl;dr.

Further than that, you'll have to understand how parentage works, which to be honest, is best seen and experienced rather than taught. Best way to learn it is by playing around with the Slice Collection Editor in custom, or by looking at the Slice Debug in gam.exe by hitting F8 and finding it so you can see how things are laid out.
ArtimusBena
Slime Knight
Posts: 205
Joined: Thu Nov 16, 2017 5:22 am

Post by ArtimusBena »

The first question is... why do you need a slice? I'm a big proponent of slice use, however... you can just use a string for this. And it would look exactly the same. (Unless you're planning for special effects).


http://hamsterrepublic.com/ohrrpgce/nig ... t-settimer

Where the

Code: Select all

string
argument is, pick a string id you're not using. For this example: string 0.

Code: Select all

set timer (1, 120, 18, @TRIGGEREDSCRIPT, 0)
Then:

Code: Select all

center string at (0, 160, 12)



In "@TRIGGERSCRIPT": clear string (0)
Last edited by ArtimusBena on Wed Aug 19, 2020 8:37 am, edited 1 time in total.
Do you make love with the same urgency you make games?
User avatar
Seamus Moore
Slime
Posts: 19
Joined: Mon Mar 16, 2020 9:39 pm
Location: Seamus Moore's House

Post by Seamus Moore »

Thanks for the help, Both replies to my post were useful to know, It turned out extremely simple to place a timer.
dQw4w9WgXcQ
Post Reply