Author Topic: Advanced Custom Input Script  (Read 494 times)

Zefk

  • Sr. Member
  • ****
  • Posts: 482
  • Just helping Solarus
    • View Profile
    • Zelzec Business
Advanced Custom Input Script
« on: November 04, 2016, 07:40:32 am »
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)
« Last Edit: November 08, 2016, 05:54:06 am by Zefk »

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1008
    • View Profile
Re: Advanced Custom Input Script
« Reply #1 on: November 04, 2016, 08:56:51 am »
Code: Lua
  1. local digit_1st_disable = false
  2. local digit_2nd_disable = false
  3. local digit_3rd_disable = false
  4. local digit_4th_disable = false
  5. local digit_5th_disable = false
  6. local digit_6th_disable = false
  7.  
  8. --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"
  9. local digit_1st_x = 75
  10. local digit_1st_y = 70
  11.  
  12. local digit_2nd_x = 60
  13. local digit_2nd_y = 70
  14.  
  15. local digit_3rd_x = 45
  16. local digit_3rd_y = 70
  17.  
  18. local digit_4th_x = 30
  19. local digit_4th_y = 70
  20.  
  21. local digit_5th_x = 15
  22. local digit_5th_y = 70
  23.  
  24. local digit_6th_x = 0
  25. local digit_6th_y = 70
  26.  

Code: Lua
  1.    digit_switch_1st = {},
  2.    digit_switch_2nd = {},
  3.    digit_switch_3rd = {},
  4.    digit_switch_4th = {},
  5.    digit_switch_5th = {},
  6.    digit_switch_6th = {},
  7.  

Code: Lua
  1.    --load the nine first local digits images from the left.
  2.    zero_img = sol.surface.create("input_number/numbers/0.png"),
  3.    one_img = sol.surface.create("input_number/numbers/1.png") ,
  4.    two_img = sol.surface.create("input_number/numbers/2.png"),
  5.    three_img = sol.surface.create("input_number/numbers/3.png"),
  6.    four_img = sol.surface.create("input_number/numbers/4.png"),
  7.    five_img = sol.surface.create("input_number/numbers/5.png"),
  8.    six_img = sol.surface.create("input_number/numbers/6.png"),
  9.    seven_img = sol.surface.create("input_number/numbers/7.png"),
  10.    eight_img = sol.surface.create("input_number/numbers/8.png"),
  11.    nine_img = sol.surface.create("input_number/numbers/9.png"),
  12.  
Why don't you use arrays?
For example:
Code: Lua
  1.    --load the nine first local digits images from the left.
  2. local digit_imgs = {}
  3. for i = 0, 9 do
  4.    digit_imgs[i] = sol.surface.create("input_number/numbers/" .. i .. ".png")
  5. end
  6.  
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.
« Last Edit: November 04, 2016, 09:27:41 am by Christopho »

Zefk

  • Sr. Member
  • ****
  • Posts: 482
  • Just helping Solarus
    • View Profile
    • Zelzec Business
Re: Advanced Custom Input Script
« Reply #2 on: November 04, 2016, 09:11:36 am »
Quote
Why don't you use arrays?
For example:
Code: Lua
  1.    --load the nine first local digits images from the left.
  2. local digit_imgs = {}
  3. for i = 0, 9 do
  4.    digit_imgs[i] = sol.surface.create("input_number/numbers/" .. i .. ".png")
  5. end
  6.  

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.

Quote
number 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
  1. 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.
« Last Edit: November 05, 2016, 09:48:18 am by Zefk »

Zefk

  • Sr. Member
  • ****
  • Posts: 482
  • Just helping Solarus
    • View Profile
    • Zelzec Business
Re: Advanced Custom Input Script
« Reply #3 on: November 08, 2016, 05:26:42 am »
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.
« Last Edit: November 08, 2016, 05:28:51 am by Zefk »