Search found 34 matches

by kendoctor
Thu Aug 20, 2020 11:34 am
Forum: Modding help
Topic: About LuaObj.valid property
Replies: 3
Views: 1101

Re: About LuaObj.valid property

--- Clone carriage from the old.
-- @tparam class<Carriage> old_carriage
function Carriage:clone(old_carriage)
local restore = function(e)
-- @todo more accurate and flexiable is to check unit_number in CarriageDoorManager
if e.source.name ~= "player-port" then return end
local old_doors = old ...
by kendoctor
Thu Aug 20, 2020 11:28 am
Forum: Modding help
Topic: About LuaObj.valid property
Replies: 3
Views: 1101

Re: About LuaObj.valid property


/c
global.entity = game.player.selected
game.print(global.entity.valid) -- true
game.player.selected.destroy()
game.print(global.entity.valid) -- false


If you store anything in global, you must always check .valid because something else destroy it.


thx your reply.
should i consider like ...
by kendoctor
Thu Aug 20, 2020 3:23 am
Forum: Modding help
Topic: About LuaObj.valid property
Replies: 3
Views: 1101

About LuaObj.valid property

I'm still confused for this valid property.

How, when, what trigger this property to be false and luobj is still not nil ?

As i discovered, when deleted a surface in one event, the surface will be actually destroyed in next tick. It seems this will happen. (I did not test it)
by kendoctor
Wed Aug 19, 2020 3:34 pm
Forum: Modding help
Topic: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful
Replies: 20
Views: 3500

Re: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful



1. undentify entity -> search in one table table[id] -> get data to indentify role. flat strategy. but all roles in one table
2. undentify entity but has a private field, string -> split into parts, get role info -> then push into role table


Stringly typed system. But what is the difference ...
by kendoctor
Wed Aug 19, 2020 3:00 pm
Forum: Modding help
Topic: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful
Replies: 20
Views: 3500

Re: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful



then, find all doors
you iterating all over this table ?


Now you are shifting onto a different problem. First one was to convert entity into data held in mod context, that can be done using unit_number or the backup one using registration. Second one is a different problem to solve. If you ...
by kendoctor
Wed Aug 19, 2020 2:23 pm
Forum: Modding help
Topic: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful
Replies: 20
Views: 3500

Re: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful


I have a global.by_id that maps any entity unit_number I'm interested in to my internal data for that entity. If the entity name isn't enough to figure out the role then my internal data has a type field.

So it's always simple to do stuff:


local data = global.by_id[entity.unit_number]
if data ...
by kendoctor
Wed Aug 19, 2020 1:39 pm
Forum: Modding help
Topic: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful
Replies: 20
Views: 3500

Re: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful



This would increase memory usage
If store the private data in global, is also consuming memory. That's the same.


Please read more careful. If you have 1000000 entities on map (lets say, trees, belts, biters, everything), adding 16 extra bytes to every entity would immediately give 16MB of ...
by kendoctor
Wed Aug 19, 2020 12:04 pm
Forum: Modding help
Topic: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful
Replies: 20
Views: 3500

Re: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful


Unlikely to be ever implemented. This would increase memory usage for every entity or would require separate map implemented outside of the entity itself. There would be also issue with lifetime of such variable (if it would go over single tick, would need to be save/loaded) and would have to be ...
by kendoctor
Wed Aug 19, 2020 7:34 am
Forum: Modding help
Topic: If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful
Replies: 20
Views: 3500

If LuaObject or LuaEntity has a property for caching private data, even a string value. Helpful

In some cases, I need a property to temp store plain value. For example

Surface clone area will trigger on_entity_cloned.
if the origina entity which i used for a door or portal. I need listen this event to compare a cache table to find the cloned entity.
doors, a cache table , store all door ...
by kendoctor
Mon Aug 17, 2020 11:52 am
Forum: Modding help
Topic: serpent.block seems having bug[solved]
Replies: 2
Views: 886

Re: serpent.block seems having bug


serpent.block is trying to avoid writing variables it already printed in case of cyclic or multiple references. In that case, it will print a placeholder value - here it will be "0" - but due to the nature of serpent.block, it will not print the fixing part that links all the references (it would ...
by kendoctor
Mon Aug 17, 2020 11:28 am
Forum: Modding help
Topic: serpent.block seems having bug[solved]
Replies: 2
Views: 886

serpent.block seems having bug[solved]

using serpent.block, dump this
["facto.train.carriagefactory"] = {
instanced = {
["31"] = {
factoobj = {
__self = "userdata"
},
order = 1,
train = {
carriages = {
0
},
factoobj = {
__self = "userdata"
},
id = 2,
surface = {
__self = "userdata"
}
}
}
}
},
["facto.train ...
by kendoctor
Thu Aug 13, 2020 12:29 pm
Forum: Modding help
Topic: Give my understanding about desync problems.
Replies: 6
Views: 1660

Re: Give my understanding about desync problems.

You guys focus the details. That's not what I cares about so much.
I just tell a very simple basis, a very simple diagram, a very simple mechanism to clear when, where, how will cause desync problems . Even somewhere i guessed wrong.
Thanks all of your reply. :D :D :D :D :D :D 不要太杠精
by kendoctor
Wed Aug 12, 2020 11:59 pm
Forum: Modding help
Topic: About on_loaded event
Replies: 27
Views: 4817

Re: About on_loaded event





Avoid desyncs by avoiding to do anything the manual tells you to not do, and don't do anything that gives defferent clients different states for the same tick. You don't have to figure out what clients are doing what etc, because then you are doing something wrong. You don't think about ...
by kendoctor
Wed Aug 12, 2020 11:52 pm
Forum: Modding help
Topic: About on_loaded event
Replies: 27
Views: 4817

Re: About on_loaded event




Avoid desyncs by avoiding to do anything the manual tells you to not do, and don't do anything that gives defferent clients different states for the same tick. You don't have to figure out what clients are doing what etc, because then you are doing something wrong. You don't think about ...
by kendoctor
Wed Aug 12, 2020 11:46 pm
Forum: Modding help
Topic: Give my understanding about desync problems.
Replies: 6
Views: 1660

Re: Give my understanding about desync problems.

Why I seperately reposted this content. I think, lots of new moders have the confusion about the desync problems. New does not mean has no any programming experience. Like me, I have engaged in programming at least 25 years. Even this, only depending on read offical doc, you can not fully understand ...
by kendoctor
Wed Aug 12, 2020 11:08 pm
Forum: Modding help
Topic: About on_loaded event
Replies: 27
Views: 4817

Re: About on_loaded event


Avoid desyncs by avoiding to do anything the manual tells you to not do, and don't do anything that gives defferent clients different states for the same tick. You don't have to figure out what clients are doing what etc, because then you are doing something wrong. You don't think about ...
by kendoctor
Wed Aug 12, 2020 3:37 pm
Forum: Modding help
Topic: Give my understanding about desync problems.
Replies: 6
Views: 1660

Re: Give my understanding about desync problems.

Another mentioned here. ramdom() function ,if facto rewrites this method using game.tick time. that will be no problem for player A and player B
I just gave an example. random things always can he happened.
by kendoctor
Wed Aug 12, 2020 3:19 pm
Forum: Modding help
Topic: Give my understanding about desync problems.
Replies: 6
Views: 1660

Give my understanding about desync problems.

1. Game saved. With a gameState = N
2. One player A join -> download the save with gameState = N -> in his client on_load event triggered => Pass gameState into script => This is point
3. Player A going to play -> triggered M*event -> gameState changed to X, at this time another player B join
4 ...
by kendoctor
Wed Aug 12, 2020 3:13 pm
Forum: Modding help
Topic: About on_loaded event
Replies: 27
Views: 4817

Re: About on_loaded event


1) If every time on_load triggers you always do game_data = global.facto and never assign anything else then that works fine (unless the game says you can't).

The important part is that after on_load all players must have the same game state. And only the newly joined player runs on_load afaik ...
by kendoctor
Wed Aug 12, 2020 1:47 pm
Forum: Modding help
Topic: Could I associate extra data or private data for an entity object
Replies: 4
Views: 1353

Re: Could I associate extra data or private data for an entity object

mrvn wrote: Wed Aug 12, 2020 1:06 pm
kendoctor wrote: Sun Aug 09, 2020 11:37 am thx, actually , i want a proerty of entity to store this data.
Can't. That wouldn't be stored in save games and therefore lost when you load it again.
thx your reply. In old vb programs, mcrosoft using this tech for vb objects to store private data. That's why i ask this question

Go to advanced search