-
Welcome to skUnity!
Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.
If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!
Now, what are you waiting for? Join the community now!
Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
How to comment properly
-
Why you are here
You need to comment your code. Under any circumstances, not commenting your code will cause more problems.
In this short tutorial, I will show the correct way of commenting code.
Commenting
[[ Show what it means ]]
Generally, lines on the code speak for themselves
example
Code (Text):- function aPlusb(a: number, b: number) :: number:
- return {_a}+{_b}
However, you need to code on these types of code
- code that has complex data structures
- code that uses compact code expressions
- code that seems to have unintuitive logic flow
- and generally, every code that might need some extra explanation
Code (Text):- function ChatString_CutRight(t: text, l: integer) :: string:
- set {_text::*} to ChatString_ColorToBlank({_t}) split at ""
- set {_textl} to size of {_text::*}
- delete {_text::%{_l}%}
- set {_returntext} to ""
- set {_pxl} to 0
- loop {_text::*}:
- set {_nextcharl} to ChatString_ReturnPixelLength(loop-value)
- add {_nextcharl} to {_pxl}
- if {_pxl} <= {_l}:
- set {_returntext} to "%{_returntext}%%loop-value%"
- else:
- exit loop
- set {_returntext} to substring of {_t} from 1 to length of {_returntext}
- return {_returntext}
So, should you comment as much as you can? no
Here is a list of the comments you should not include
Code (Text):- # comments that literally explain the code
- if {_hang} > 3: # this code will execute if hang is greater than 3
- # fix
- if {_hang} > 3: # check if player's total hangs are over 3 times => game over
- # comments that tell what the type of that line is
- trigger: # this is a trigger
- # fix
- trigger:
- # you should not comment on lines that are keywords and widely used.
- # commenting "this is a trigger" doesn't help anything
- # commenting useless information
- message "activated" to player # this code is just to show that the code is properly working therefore if it is not sent, the code has a problem
- # fix
- message "activated" to player # debug message
- # commenting after a long string
- set {_base64} to "
- TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
- IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
- dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
- dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
- ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=
- " # this is the text base64
- #fix
- # text base64 of paragraph
- set {_base64} to "
- TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
- IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
- dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
- dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
- ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="
- # commenting vague meanings
- set {_ytho} to "I--eiHiens" # F/Prt
- # fix
- set {_ytho} to "I--eiHiens" # format printing
- # and lastly,
- # excessive comments about your credits
- function thisFunc():
- # CREDITS: SomeUsername
- # DO NOT DISTRIBUTE
- # ----------------------------------------
- # created by: SomeUsername
- # ----------------------------------------
- # best code ever
- # might add more examples later. last update 2020/2/5
Code from skUnity Discord
Code (Text):- command /sharigan [<text>]: # The Command
- trigger: #what Triggers it?
- if player has permission "sharigan.use": #if player has permission then keep going
- if {permsharigan.%player%} is not set: #if the variable it not set, well then
- set {permsharigan.%player%} to true #set it
- set {oldhelmet::%player%} to helmet of player # Store old helmet
- make player execute command "me Activated Sharigan" #just to show that its activated
- message " &f&k------ &7&lSharigan Activated 300s! &f&k------" #again to show its activated
- execute console command "effect give %player% minecraft:speed 1200 3" #give speed boost (just temp to see it work and it does)
- #set item data of player's helmet to "minecraft:diamond_shovel:430" #Set the helmet to our custom model
- set helmet of the player to a diamond helmet# test to see if it works
- wait 300 seconds #hold your horses
- if {permsharigan.%player%} is true: #if its still on then shut if off now
- make player execute command "shariganoff" #execute order 66
- stop #hammer time
- stop #x2
- if {permsharigan.%player%} is true: #deactivate
- delete {permsharigan.%player%}
- execute console command "effect give %player% minecraft:speed 1 4"
- message " &f&k------ &7&lSharigan Deactivated &f&k------" #now its off
- stop
- else: message " &7>> &cYou have not awakened the Sharigan!" #no perms no useage
Code (Text):- command /sharigan [<text>]:
- trigger:
- if player has permission "sharigan.use":
- #if true, activate sharigan
- if {permsharigan.%player%} is not set:
- # not set => activate
- # true => deactivate
- set {permsharigan.%player%} to true
- set {oldhelmet::%player%} to helmet of player
- # Store old helmet
- make player execute command "me Activated Sharigan" # debug message
- message " &f&k------ &7&lSharigan Activated 300s! &f&k------"
- # give speed boost and change player's properties
- execute console command "effect give %player% minecraft:speed 1200 3"
- set item data of player's helmet to "minecraft:diamond_shovel:430
- # helmet custom model
- set helmet of the player to a diamond helmet
- # debug
- wait 300 seconds
- if {permsharigan.%player%} is true:
- # true => shut if off
- make player execute command "shariganoff"
- stop
- stop
- else if {permsharigan.%player%} is true:
- # deactivate
- delete {permsharigan.%player%}
- # change variable to not set state for further activation
- execute console command "effect give %player% minecraft:speed 1 4"
- message " &f&k------ &7&lSharigan Deactivated &f&k------"
- # off msg
- stop
- else:
- message " &7>> &cYou have not awakened the Sharigan!"
- #no perm message
Code (Text):- function ChatString_CutRight(t: text, l: integer) :: string:
- # this function returns a text that cuts the text to the targeted pixel
- # set the array of text
- set {_text::*} to ChatString_ColorToBlank({_t}) split at ""
- set {_textl} to size of {_text::*}
- delete {_text::%{_l}%}
- # the final return string
- set {_returntext} to ""
- # set the total pixel length to 0
- set {_pxl} to 0
- # loop every character and add it to the pixel count
- loop {_text::*}:
- set {_nextcharl} to ChatString_ReturnPixelLength(loop-value)
- add {_nextcharl} to {_pxl}
- if {_pxl} <= {_l}:
- # if condition is true; means we can add a new character to the result string
- set {_returntext} to "%{_returntext}%%loop-value%"
- else:
- # if it exceeds exit the loop and process the return text
- exit loop
- # because the return text has blank characters
- set {_returntext} to substring of {_t} from 1 to length of {_returntext}
- # return the final text
- return {_returntext}
Update log
- 2020/2/5 created page