Advanced Custom Input Script

Started by Zefk, November 04, 2016, 07:40:32 AM

Previous topic - Next topic
November 04, 2016, 07:40:32 AM Last Edit: November 08, 2016, 05:54:06 AM by Zefk
About:
You can used this script to enter numbers. This is my new advanced custom input script. It is a lot better than my old one.

Download Script with Sample Quest:
You can download the old 6 digit input max demo: here
You can download the recent 9 digit input max demo: here

Changes:
-Code has been massively simplified.
-The script goes up to the 9th local digit, 999,999,999 max.

Gif Preview: (Not lagging, just missing a lot of frames)


YouTube:
Advanced Custom Input Script

Features:
1.Use bitmaps(png,etc) for numbers or any alien numbering system images
2.Use of sol.text_suface for font packages (Any Solarus compatible font package you want)
3.The script goes up to the 9th local digit, 999,999,999 max.
4.Inputs go by exact numbers. Ex: 5,112,2121,3225,43474,503030, etc.
5.The ability to position or coordinates of the numbers, highlight blocks, and background to different locations on the screen.
6.The ability to disable numbers or digit places.
7.Easy to change! Go down to the comment, "CHANGE SETTINGS AREA:" at the beginning of the script.
8.Have the purple semi-transparent image block in the demo go across the X-axis or up the y-axis
9.A RGB color reference comment list at the end of the script
10.The ability to easily change the font in, "CHANGE SETTINGS AREA:."
11.Easily change the font color in, "CHANGE SETTINGS AREA:." Uses RGB color, so check the reference list at the end of the script.
12.Easily change the font size in, "CHANGE SETTINGS AREA:."

Script:
Attached to this post. Too long for the post apparently. (Login to view attachment)

November 04, 2016, 08:56:51 AM #1 Last Edit: November 04, 2016, 09:27:41 AM by Christopho
Code (lua) Select

local digit_1st_disable = false
local digit_2nd_disable = false
local digit_3rd_disable = false
local digit_4th_disable = false
local digit_5th_disable = false
local digit_6th_disable = false

--Move the digit around. The spacing goes by 15. 0,15,30,45,60,75 (You can change this) Remember to change "multi_highlight_draw_spacing = 15"
local digit_1st_x = 75
local digit_1st_y = 70

local digit_2nd_x = 60
local digit_2nd_y = 70

local digit_3rd_x = 45
local digit_3rd_y = 70

local digit_4th_x = 30
local digit_4th_y = 70

local digit_5th_x = 15
local digit_5th_y = 70

local digit_6th_x = 0
local digit_6th_y = 70


Code (Lua) Select

   digit_switch_1st = {},
   digit_switch_2nd = {},
   digit_switch_3rd = {},
   digit_switch_4th = {},
   digit_switch_5th = {},
   digit_switch_6th = {},


Code (lua) Select

   --load the nine first local digits images from the left.
   zero_img = sol.surface.create("input_number/numbers/0.png"),
   one_img = sol.surface.create("input_number/numbers/1.png") ,
   two_img = sol.surface.create("input_number/numbers/2.png"),
   three_img = sol.surface.create("input_number/numbers/3.png"),
   four_img = sol.surface.create("input_number/numbers/4.png"),
   five_img = sol.surface.create("input_number/numbers/5.png"),
   six_img = sol.surface.create("input_number/numbers/6.png"),
   seven_img = sol.surface.create("input_number/numbers/7.png"),
   eight_img = sol.surface.create("input_number/numbers/8.png"),
   nine_img = sol.surface.create("input_number/numbers/9.png"),

Why don't you use arrays?
For example:
Code (lua) Select
   --load the nine first local digits images from the left.
local digit_imgs = {}
for i = 0, 9 do
   digit_imgs[i] = sol.surface.create("input_number/numbers/" .. i .. ".png")
end

Because of that your script has a lot of duplicated code. And it is not flexible, for example if someone wants another number of digits than 6 there is no easy way.

November 04, 2016, 09:11:36 AM #2 Last Edit: November 05, 2016, 09:48:18 AM by Zefk
Quote
Why don't you use arrays?
For example:
Code ( lua) Select
   --load the nine first local digits images from the left.
local digit_imgs = {}
for i = 0, 9 do
   digit_imgs[i] = sol.surface.create("input_number/numbers/" .. i .. ".png")
end

I did not know it was possible to load images like that. Seems this script will become shorter in the future. Thank you for letting me know about this.

Quotenumber of digits than 6 there is no easy way.
I think your example gave me an idea on how to break that limit. I will try the algorithm I thought of in the future, but I doubt many will need to deposit or withdraw 999,999. I can always extend it for a fee. I might do it when I make a space game because digits larger than 6 for input will be needed, but for now I want to finish my other scripts. I do not like to linger on one script for too long, but this was a huge improvement over my last script. Maybe next month because this script is only meant to have 6 digits, so the algorithm would be a new script.

Code ( lua) Select
draw_imgs[i]:draw(screen,.....
I completely overlooked doing this during drawing too. A Lot of drawing code will vanish for sure, but it did not take long to copy, paste, and replace the minor changes for each digit. I thank you for the tip. I did this in another script, but it seems I forgot to do it.

November 08, 2016, 05:26:42 AM #3 Last Edit: November 08, 2016, 05:28:51 AM by Zefk
Update:

Changes:
-Code has been massively simplified.
-The script goes up to the 9th local digit, 999,999,999 max.

Download:
You can download the recent 9 digit input max demo: here

I updated the attachment as well.