Updating alert_message of programmable speaker

Place to get help with not working mods / modding interface.
hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

Updating alert_message of programmable speaker

Post by hreintke »

Hi,

I am trying to update the alert_message of a programmable speaker within a mod.
Will use that later on when I create an "own entity" based on the speaker.

When running this code with a speaker selected I always get the current value, it never updates.

Code: Select all

/c
s = game.player.selected
if s.name == "programmable-speaker" then 
   game.player.print("am  = " .. s.alert_parameters.alert_message)
   s.alert_parameters.alert_message = "mytest"
   game.player.print("am1 = " .. s.alert_parameters.alert_message)
end
Using the GUI I can update the value.

Any hint on what I am missing ?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Updating alert_message of programmable speaker

Post by eradicator »

You probably have to write the whole alert_parameters table, i.e.
local x = entity.alert_parameters
x.alert_message = 'mymessage'
entity.alert_parameters = x

at least that's what the API doc says.
hreintke
Fast Inserter
Fast Inserter
Posts: 115
Joined: Mon Sep 04, 2017 6:52 pm
Contact:

Re: Updating alert_message of programmable speaker

Post by hreintke »

Thanks, that was the issue.

Is this the part of the API doc you are referring to ?

Code: Select all

Luaentity 
....
parameters :: ProgrammableSpeakerParameters [RW]	
alert_parameters :: ProgrammableSpeakerAlertParameters [RW]	
....
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Updating alert_message of programmable speaker

Post by eradicator »

Yea. You can see how it says [RW] == read and write. Whereas the properties of the ProgrammableSpeakerAlertParameters (if you click the link) do not say they can be written or read, which suggests they're a table that needs to be written as a whole.
Post Reply

Return to “Modding help”