Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements #2

Open
SvarogZ opened this issue Nov 19, 2020 · 4 comments
Open

improvements #2

SvarogZ opened this issue Nov 19, 2020 · 4 comments

Comments

@SvarogZ
Copy link

SvarogZ commented Nov 19, 2020

Please check all cycles and local variables across the code.
Please see comments below

if core ~= nil then
	 local elementsIdList = core.getElementIdList()
	 for _,id in pairs(elementsIdList) do -- use ipairs instead
		local elementType = core.getElementTypeById(id):lower()
		if elementType:find("container") then
			name = core.getElementNameById(id) -- should be local
			if string.match(name, "CH_") or string.match(name, "C_") then
			temp = split(name, "_") -- should be local			 
 				table.insert(containersIdList , {id, temp[1], string.match(temp[2], "%d+"), string.sub(temp[2], -1), temp[3], hasValue(temp[4])})	
				--1: id, 2: type, 3: containercount, 4: containersize, 5: material, 6: description
		end						
		end
	 end
end

Improvement to color the line:

local function getColor(number)
	if number < 50 then
		return "rgb(255," .. utils.round(utils.map(number, 0, 40, 100, 255)) .. ",0)"
	else
		return "rgb(" .. utils.round(utils.map(number, 40, 100, 255, 155)) .. ",255,0)"
	end
end

This code cannot work with different containers in one hub.
Please consider specifying the volume/capacity in the name of the hub.

@carmopereira
Copy link
Owner

Thanks for the input!

For the color function there's no no need to place more utils, rounds (more cpu) and take down the "minimum" "medium" and "max" threshold warning. For color conventions, I do endorse the use of hexs and web colors thru names. You can still use rgb, but it's a bit, duhhhh. (unless u need to do a transparency, and in that case, you should use an argb).
I could make the color variables so you change them in parameters (if you please you can type rgb(x,y,z) if you like. If you don't like the 3 color settings, you can just workaround the settings.

For now I will not make different containers in one hub. We have character limit on the names (30), and it will be to damn confuse to accomplish that.

Last version brought the capacity of multiple "standalone" containers with the same ore, but but different sizes within one container hub is very tricky. CH_1L_3M_4S_IRON ?? Don't have space left...

For the temp variable in the first quote, i could make it local. It will prevent future unpleasantness if I reuse that name.

Thanks!

@SvarogZ
Copy link
Author

SvarogZ commented Nov 19, 2020

Yes, the character limit does not allow to type everything.
This is a brilliant idea and I started to use it in my code.
However, I use direct entering "uid" of the hub. If this hub on the same screen it's easier. No neer to search it in a cycle. We have around 10k elements :)

Thank you!

P.S. if you add a formatted version of your code, it will be easier for visitors to give you feedback. Not everyone wants to copy this to the game or parse it.

@SvarogZ
Copy link
Author

SvarogZ commented Nov 19, 2020

Alternatively, you can use the capacity instead: CH_196.0_IRON or CH_IRON_196.0

@carmopereira
Copy link
Owner

Added the locals on the core code.
Don't quite understand why I should change from pairs to ipairs.
other idea to avoid another cycle is to store the uids in the database. i'm uncertain if that helps, or how much miliseconds will be affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants