sleep mode for programmable block(PB)

Twotwinbrothers shared this feedback 6 years ago
Submitted

it should be nice if a PB can be put in sleep mode .until it gets a new argument.

i like to do this whitout a timerblock.


like this: if PB.CustomName don't contains "sleep" it stops the auto update

Program(){

if (!Me.CustomName.Contains("sleep")){
Runtime.UpdateFrequency=UpdateFrequency.Update1;

}
}
the example will not work, it can't read the CustomName somehow.

Replies (6)

photo
1

Why ?


You've already solved it with quite simple code ;-)

photo
1

yes i that so , this code will not work. I think this Program() will not support it , it is not a void or method or is it?


and why. multiplayer. you dont want to run if it is not needed anymore. til the script get a new argument.

photo
1

Program()
{
	// no change in Runtime.UpdateFrequency
}

void Main(string argument, UpdateType updateSource)
{
	if ((updateSource & (UpdateType.Terminal | UpdateType.Trigger | UpdateType.Script | UpdateType.Mod)) != 0)
	{
		if ("start".Equals(argument))
			Runtime.UpdateFrequency = UpdateFrequency.Update1;
		if ("stop".Equals(argument))
			Runtime.UpdateFrequency = UpdateFrequency.None;
	}
	
	if ((updateSource & UpdateType.Update1) != 0)
	{
		// stuff to do
	}
}

photo
1

Sorry, I wrote it with argument in mind ... what you aimed to do cannot be done in constructor, you must do it in Main() method ...

here is correct code:


Program()
{
	// no change in Runtime.UpdateFrequency
}


void Main(string argument, UpdateType updateSource)
{
	if ((updateSource & (UpdateType.Terminal | UpdateType.Trigger | UpdateType.Script | UpdateType.Mod)) != 0)
	{
		if (!Me.CustomName.Contains("sleep")) {
			Runtime.UpdateFrequency=UpdateFrequency.Update1;
		}

		// do something with argument if you please
	}
	
	if ((updateSource & UpdateType.Update1) != 0)
	{
		// stuff to do
	}
}

photo
1

Basically updateSource Terminal is from "run" button in terminal, Trigger is by button, timer, air vent etc, script is from other script.

Mod is probably from another mod - I never encountered it.


Program() constructor is ran only seldom - when the program block is recompiled or loaded from save game ...

You should do only basic initialization there.

You have to do your update switching logic in Main() method.

photo
1

i ended up doing it this way. thank for your help Domingo.

	Program(){
	Runtime.UpdateFrequency=UpdateFrequency.Update1;
	}

	void Main(string arg)
	{
	if(arg.Contains(open)){
	Runtime.UpdateFrequency=UpdateFrequency.Update1;
	Me.CustomName=(Me.CustomName.Replace(" sleep",""));
	}
	if(Me.CustomName.Contains("sleep")){
	Runtime.UpdateFrequency=UpdateFrequency.None;
	}

}}Is there a reason why you need to do this? It works fine without it.
if ((updateSource & (UpdateType.Terminal | UpdateType.Trigger | UpdateType.Script | UpdateType.Mod)) 

photo
1

If you were to receive messages via antenna then it would be very important to distinguish between messages and commands.

photo
Leave a Comment
 
Attach a file