Scripts / How To Shorten Code

Author
Message
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 2nd Jun 2019 00:04 Edited at: 2nd Jun 2019 00:04
Hey all,

I'm looking for a better way to optimize my code better so im using less. For example:

if variable1 == 1 and variable2 == 0 or variable1 == 1 and variable2 == 50 then


Is there a way i can avoid repeating the variable2 == 1 check when using an "or" ?
Youtube - Teabone3 | Store Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
perelect
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 2nd Jun 2019 03:09
Quote: "Is there a way i can avoid repeating the variable2 == 1 check when using an "or" ?"


Do you mean " variable1 == 1" in the above
If so this will work.
I always use ( ) around the or just so you can see what you are checking, but it will work without them.

Desktop: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz, Windows 10 Pro, 64-bit, 16 GB Ram, ASASUS Geforce TURBO GTX1080 8GB, 34" 21:9 2560x1080 Full HD UltraWide IPS Monitor

[RIP] Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)
PT V9.0 3DMark=377, Passmark=1222.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 2nd Jun 2019 19:10
Just call them v1, v2 etc.
Been there, done that, got all the T-Shirts!
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 2nd Jun 2019 20:55
wow thank you soooo much this will clean up my scripts a whole lot.
Youtube - Teabone3 | Store Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 3rd Jun 2019 23:41 Edited at: 3rd Jun 2019 23:52
with this function:

you can do:
if variable1 == 1 and is_value_in(variable2,{0,50}) then

and the whole script:


of course perelect´s parts is more efficient, but for 6 to 7 values, mine is more readable and shorter
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 4th Jun 2019 01:13
As the request was to make the code smaller:


Does the same thing.
Been there, done that, got all the T-Shirts!
PM
Corno_1
GameGuru Tool Maker
14
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 4th Jun 2019 13:02 Edited at: 4th Jun 2019 13:03
Quote: "As the request was to make the code smaller:"

The request was not to make it smaller
Quote: "Is there a way i can avoid repeating the variable2 == 1 check when using an "or" ?"


Never troll
Ebe Editor Free - Build your own EBE structures with easy and without editing any text files
Thread and Download
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 4th Jun 2019 19:34
"How to shorten code" is the title of the thread!
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 7th Jun 2019 15:18 Edited at: 7th Jun 2019 15:19

Since we're having fun and games
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 7th Jun 2019 15:49 Edited at: 7th Jun 2019 15:50
!false
(It’s funny because it’s true.)



Only a programmer would understand this.

A programmer’s wife asks: “Would you go to the shop and pick up a loaf of bread? And if they have eggs, get a dozen.”
The programmer returns home with 12 loaves of bread.
“They had eggs.”

Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 7th Jun 2019 15:54
ooh this is a good one, see if you can get the meaning

[“hip”,”hip”]

Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 7th Jun 2019 18:17
hip hip array
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 7th Jun 2019 19:17
@ Belidos
6 men working on the shop.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 7th Jun 2019 19:17
@ Belidos
6 men working on the shop.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 7th Jun 2019 19:18
Sorry, double post.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 7th Jun 2019 23:31
Youtube - Teabone3 | Store Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 12th Jun 2019 02:35 Edited at: 12th Jun 2019 04:42
On the similar topic, I'm trying to create a single variable i could use that contains numerous operations. For instance PlayerDistance im trying to make an equivalent Entity Distance from another Entity.

I've got this working with



But am curious how i could go about making this easier to use elsewhere. Similar to:
. I would like something similar as its much easier to compare to later with greater or lesser checks.

From what i understand is GetPlayerDistance(e) is created with:


Would I have to create something similar to this for entities? I'm trying to understand the math

EDIT: ah solved my own problem

Store Assets - Store Link

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 12th Jun 2019 09:30
i have a whole bunch in my thread
Quote: "Functions / custom commands
detect if player is looking at an object
https://forum.game-guru.com/thread/207801?page=7#msg2515459
detect if an object is looking at an object
https://forum.game-guru.com/thread/207801?page=12#msg2538121
check if an object is looking at the player
https://forum.game-guru.com/thread/207801?page=12#msg2541409
get distance between 2 objects (not player) & rotate an object to another object (not player)
https://forum.game-guru.com/thread/207801?page=5#msg2500807
rotate an object to co-ords instantly
https://forum.game-guru.com/thread/207801?page=14#msg2549716
rotate an object to co-ords slowly
https://forum.game-guru.com/thread/207801?page=14#msg2548949
auto sized Panel and Text in 1 function (thanks to amenmoses)
https://forum.game-guru.com/thread/207801?page=23#msg2600701"
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Jun 2019 20:11
There are also similar functions in utillib.
Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Jun 2019 09:43
Quote: "There are also similar functions in utillib. "

and better at that but one i add is the one requested, the function to compare a distance and get the actual result so it can be stored and compared - your CloserThan function returns true / false
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-12-22 14:14:51
Your offset time is: 2024-12-22 14:14:51