Retro Gadgets

Retro Gadgets

Not enough ratings
Display Text to a screen(and change the value with a knob)
By thecapitankaty
this is a guide on how to display text and change it with a knob going from -100 to 100

here's the final project if you want to look at it
https://steamproxy-script.pipiskins.com/sharedfiles/filedetails/?id=3246663521
   
Award
Favorite
Favorited
Unfavorite
Creating the gadget(and adding the components)
add 2 of the largest boards there is and stack them on top of eachother and solder them together

this will create the base of our gadget


add a knob and a screen of your choosing


feel free to add color aswell


add a CPU, ROM, and a Video Chip to the back of the gadget
a CPU is basically the 'brain' of your gadget it holds all the logic and code, the ROM is what you'll use to access inbuilt fonts, sprites, audio etc, and Video Chip is to display video.


open the multitool on the left and click the screen and connect it to the video chip

if you don't do this it will not display the text or anything on the screen
also feel free to add any stickers or any customization to your gadget
Coding(in lua)
now that you have setup your gadget lets code

open the CPU0.lua file in your assets and click edit


you can delete this


add
local video = gdt.VideoChip0
this creates a variable that contains the video chip so we don't have to constantly use
gdt.VideoChip0


we're also gonna add
local fontBasic = gdt.ROM.System.SpriteSheets["StandardFont']
this refers to the inbuilt font in Retro Gadgets. i don't know if there is anyway to add custom fonts.


inside the update function we're gonna add
video.Clear(video,color.black)
this clears the screen and makes the background black
you can make it any color though


now its time to actually add text to the screen so add
video.DrawText(video, vec2(0,0),fontBasic,"Hello, World!",color.red,color.blue)
the 'vec2(0,0)' this refers to the position of the text so play around with that, the next part is the font you don't have to change anything there, next its the text later we'll replace it with a variable but lets leave it for now, then its shows 'color.red' this is the text color change to what you want, now we have 'color.blue' this is the background color change this to what you want.

i set the text color to white and the background color to black.


like i mentioned before we're gonna create a variable for the text so a knob can change it from -100 to 100, so lets add a variable like so at the top
local num = 0

this creates a number variable called 'num' and its set to 0 by default

now we can replace "Hello, World!" with num, with no quotations


when we play the game it gives us an error, thats because its trying to display a number not a string
so we need to convert the number to a string with
tostring(num)
so replace 'num' with
tostring(num)


so when we play the game it will show the number 0.

but when we move the knob around it does nothing, thats because we need to set the num equal to whatever the knobs value is, so to do that we will replace 0 with
gdt.Knob0.Value
this replaces the 0 with whatever the knobs value is. so it can be -100 through 100.


now when we play it, we move the knob around it does not change, thats because the code is outside the update function, which means its only called once when we start the gadget, so to update it every tick we need to put the variable in the update function


now start up your gadget and see what you created.
Conclusion
thats the entire gadget done! congrats on finishing it, now you know how to add text and change it with a knob. by the way if you want you can change the knob with a slider, but make sure to make the proper changes to it, by replacing Knob0 with Slider0.

anyways if you enjoyed this guide like it and give it reward. happy coding!
3 Comments
the scrnkly 20 Dec, 2024 @ 7:40pm 
thanks, had to replace the : of the drawtext too, really cool beginner guide
thecapitankaty  [author] 20 Dec, 2024 @ 7:33pm 
try video.Clear(video,color.black) so replace the ":" with a "."
the scrnkly 20 Dec, 2024 @ 6:37pm 
your codes always has the video:Clear(video,color.black) error out even though i followed every step correctly