Jump to content

quick script to turn a Radio on ?


Agnot2006

Recommended Posts

Thanks again, I wish I could get the hang of this

So what would happen if the GetCurrentTime = 10 ? its not < or > ?

It would be included in ( GetCurrentTime >= 10 ) because the symbols >= together mean "greater than or equal to" just as they do in algebra.

 

If you mean what would happen if you changed the expression from GetCurrentTime >= 10 to just ==10, then the radio might activate if you were in tha same cell right at 10, but if you came in later, or were waiting past 10, then the radio would probably not be activated. If you use inclusive range equations like >= then your arrival time is not relevant.

 

If you said > 10 "greater than 10", when the time was exactly 10 ( GetCurrentTime = 10 ) nothing would change until the time became greater than 10, in this case. I'm not sure that the game clock keeps track of seconds with this sort of condition, so that might mean that the condition would not become 1 until game hour 11.

 

This argument though:

if ( GetCurrentTime < 10 )

set init to 0

elseif ( GetCurrentTime >= 9 )

set init to 1

would create times at 9 and 10 where you are saying that the state is both 0 and 1. Knowing Fallout 3, that could mean a crash to desktop, nothing appearing to happen, or maybe just weird sounds coming from the radio as it toggles back and forth.

Link to comment
Share on other sites

This argument though:
if ( GetCurrentTime < 10 )

set init to 0

elseif ( GetCurrentTime >= 9 )

set init to 1

would create times at 9 and 10 where you are saying that the state is both 0 and 1. Knowing Fallout 3, that could mean a crash to desktop, nothing appearing to happen, or maybe just weird sounds coming from the radio as it toggles back and forth.

Logically there should be no problem.

If the time is < 10 init is always set to 0. elseifs condition gets checked only if the previous if was not true, in this case if the time >= 10. The elseif is not needed though, else would work identically (logically at least, not necessarily in FO3). So the above code is equivalent to "If time is less than 10, set init to 0. Otherwise set it to 1". If there was two ifs instead of if and elseif or if and else, the latter if in would overrun the first one in conflicting situations (which here means 9 <= time < 10).

Link to comment
Share on other sites

Everything works great. I did have to leave the cell and re-enter to get the radio to start working, re-loading inside the cell didn’t do anything. I tried stopping and re-starting the radio and its all working fine and very stable. I tried playing the idiot switching it on and off repeatedly to see if I could get it to error, but it’s fantastic. I even changed the script name and added it to anther mod which is also fine. Again I wish these things would make sense to me.

I can’t give Kudos from work it doesn’t work, but when I get home.

Could I be cheeky and ask for the change needed so that it goes off at 10pm?

Is it something like

Begin GameMode

 

if ( GetCurrentTime < 10 )&& (GetCurrentTime>20)

set init to 0

elseif ( GetCurrentTime >= 10 ) )&& (GetCurrentTime<20)

set init to 1

endif

End

 

Thank you again for a fantastic piece of script and you expertise.

Link to comment
Share on other sites

Thank you BadPenney

Everything work’s great, I did have to leave the cell and re-enter to get the radio to work, but after that it was fine. I even tried playing the idiot and turning it off and on repeatedly and didn’t get any error. I changed the script name and added it to another mod, again it worked perfectly. I wish I could get the hang of doing this.

Could I be cheeky and ask for the changes required to make the radio go off at 10pm, is it something like:

Begin GameMode

 

if ( GetCurrentTime < 10 )&&( GetCurrentTime > 20 )

set init to 0

elseif ( GetCurrentTime >= 10 )&&( GetCurrentTime <= 20 )

set init to 1

endif

End

 

I can’t give Kudos at work it doesn’t work, but when I get home

Thank You again for your fantastic script and your expertise.

 

Sorry for the repeated post but I thought I had lost the first one then suddenly there it is

Link to comment
Share on other sites

Thank you BadPenney

Everything work’s great, I did have to leave the cell and re-enter to get the radio to work, but after that it was fine. I even tried playing the idiot and turning it off and on repeatedly and didn’t get any error. I changed the script name and added it to another mod, again it worked perfectly. I wish I could get the hang of doing this.

Could I be cheeky and ask for the changes required to make the radio go off at 10pm, is it something like:

Begin GameMode

 

if ( GetCurrentTime < 10 )&&( GetCurrentTime > 20 )

set init to 0

elseif ( GetCurrentTime >= 10 )&&( GetCurrentTime <= 20 )

set init to 1

endif

End

 

I can’t give Kudos at work it doesn’t work, but when I get home

Thank You again for your fantastic script and your expertise.

 

Sorry for the repeated post but I thought I had lost the first one then suddenly there it is

 

In debugging it usually helps to translate the code to plain english.

"If current time is less than 10 AND current time is greater than 20, then set init to 0. If the previous conditions are not true, then if current time is greater than or equal to 10 AND current time is less than or equal to 20, then set init to 1."

 

I believe in scripting it's better to learn how to solve the problems yourself than always getting a copy-paste ready code which doesn't require you to understand what you are doing, but if you can't figure out the problem yourself, I've added a spoiler below.

 

 

 

The if condition is always false. The time can never be both less than 10 and greater than 20 at the same time. If you want the radio to be always off after 10pm (22:00) then use if (GetCurrentTime >= 22 || GetCurrentTime < 10) instead of the if above. If you want the radio to turn off at 22 but still be able to manually turn it on even after 22:00, you need to do something like this (writing this off my head so there might be some typos etc):

 

Begin GameMode

if ((GetCurrentTime >= 22 || GetCurrentTime < 10) && autoOn == 1) ;the inner parentheses are required

set init to 0

set autoOn to 0

elseif (GetCurrentTime >= 10 && GetCurrentTime < 22 && autoOn == 0) ;no additional parentheses needed here

set init to 1

set autoOn to 1

endif

End

 

 

Link to comment
Share on other sites

This version is set to play between 10 am to 10 pm and be off between 10 pm and 10 am.

 

scn 0001SSVintageRadioSCRIPT

 

short IsOn

short init

ref mySelf

 

;**********************************

 

Begin onLoad

set mySelf to getSelf

End

 

;**********************************

 

Begin GameMode

 

if ( GetCurrentTime >= 22 ) || ( GetCurrentTime < 10 )

set init to 0

elseif ( GetCurrentTime >= 10 ) && ( GetCurrentTime < 22 )

set init to 1

endif

End

 

;**********************************

 

Begin GameMode

 

if ( init == 1 ) && ( IsOn == 0 )

Activate mySelf

Set IsOn to 1

elseif ( init == 0 ) && ( IsOn == 1 )

Activate mySelf

Set IsOn to 0

elseif ( init == 1 ) && ( IsOn == 2 )

Set IsOn to 1

elseif ( init == 0 ) && ( IsOn == 3 )

Set IsOn to 0

endif

End

 

;**********************************

 

Begin OnActivate

 

if ( IsActionRef Player == 1 ) && ( init == 1 ) && ( IsOn == 1 )

Activate

Set IsOn to 3

elseif ( IsActionRef Player == 1 ) && ( init == 0 ) && ( IsOn == 0 )

Activate

Set IsOn to 2

elseif ( IsActionRef Player == 1 ) && ( init == 1 ) && ( IsOn == 3 )

Activate

Set IsOn to 1

elseif ( IsActionRef Player == 1 ) && ( init == 0 ) && ( IsOn == 2 )

Activate

Set IsOn to 0

endif

End

 

;**********************************

This ( || ) means "OR".

Link to comment
Share on other sites

Having been trained to be a trainer, I have learned that people have different learning styles and different cognitive approaches. A successful trainer adapts to the learner's style rather than attempt to force the learner to adopt the trainer's style. That is a pragmatic approach. While an analytical approach is concerned with "the best way" to do things, a pragmatist is more apt to say "whatever works".

 

I believe that Agnot2006 will learn in his own way, or not. But then his thread did not begin with a request for training, only a request for a script. Since I found it an interesting puzzle, I have worked on a script designed to fit his design parameters and presented it to him.

 

Logically there should be no problem.

If the time is < 10 init is always set to 0. elseifs condition gets checked only if the previous if was not true, in this case if the time >= 10. The elseif is not needed though, else would work identically (logically at least, not necessarily in FO3). So the above code is equivalent to "If time is less than 10, set init to 0. Otherwise set it to 1". If there was two ifs instead of if and elseif or if and else, the latter if in would overrun the first one in conflicting situations (which here means 9 <= time < 10).

This may be correct, and if tested in game it seems to work the same. However, I find no advantage to writing vague conditions. On the other hand, a precise equation with no ambiguity tends to forestall any unintended programming errors.

 

A case in point, I recently tracked down a fatal error in my mod that caused the game to crash to desktop at a certain point. The culprit was a duplicated setstage command. While creating a quest I used a result script in a line of dialogue to setstage 35 of the current quest. Forgetting that, sometime later I made a script that also included the line setstage 35. The result was that the quest was told to setstage 35 while it was already at stage 35. That doesn't seem as though it should be a big problem, but it was, and it did not manifest itself immediately. Only after returning to town where the next stage of the quest would be set and attempting to save the game either manually or with an autosave did the game crash. I could take my character anywhere else for an indefinite time and savegame multiple times with no problem. Only after removing the setstage 35 command from the dialogue result script did the problem go away.

 

My conclusion is that one should leave no ambiguity, paradox or duplication in scripting and that failing to do that may cause problems that are not seemingly related or immediately apparent.

 

In debugging it usually helps to translate the code to plain english.

This is a good approach. But programming and mathematics have their own languages, and if you can learn to read and understand the equation as it is without translating then you have an advantage in fluency in the same way that you can speak any language more fluently if you can think with it rather than translating in your head first.

Link to comment
Share on other sites

...

I don't agree with everything you say, but I admit people have different tastes. I have a strong urge to defend my opinions, but currently I am too tired to write a polite yet strong response. I will try to remember to do that later.

Link to comment
Share on other sites

The part concerning giving versus hinting:

First I think we should take two facts into account. First, Agnot2006 is still learning the basic principles of scripting and haven't probably programmed much before, if at all. Second, he accepts that but plans to do more than just this one quick piece of code, which hopefully also means he wants to learn. I agree with you that there are situations where a straight answer is more helpful than trying to guide someone to the right direction, but I don't think this was like that. If-then-else logic is an absolute requirement for any kind of scripting and Agnot2006 really needs to learn it, the faster the better. It is possible he would learn it on his own, but I believed that if he was going to do that, he would've solved the problem on his own in the first place. It is important to note that I am not blaming you for giving the straight answer nor am I blaming Agnot2006 for asking. Asking is obviously never wrong and my previous point was not to tell how ready code is bad but why I am usually not providing it.

 

The second part:

Obviously using that kind of statements is not good, but unless the Beth programmers were really high when coding the script logic, there is no way that piece of code would cause any problems. Generally of course that kind of code is a sure way of losing your sanity and so it's good to discourage that, but in this case it is clear how the code works.

 

The third part:

First I want to emphasize the word "debugging". If the program is not working and you can't see the error, then it means your fluency in the programming language is not strong enough and so you need some other way of solving the problem.

 

By translating I meant merely giving the abstract variables meanings. Low-level programming usually works well enough even without that, but when you are trying to create any high-level code, such as scripts, giving the meanings can really help you see potential errors in behavior. The point is that the error is not in how you implement your thoughts but that it is your thoughts that have errors. More complex a certain script is the more important it is to understand how it is related to everything and that's where associations to real objects (even in-game objects, they are still something more than pure abstract constructs) really help.

Link to comment
Share on other sites

If ( GetCurrentTime >= 10 && GetCurrentTime < 22 )

set init to 1

Else

set init to 0

EndIf

 

 

 

That would be perfectly fine. There is no "Vague" in programming. If you programmed every logical step you wanted to make for every statement, you would end up with twice the code you needed to write. It's either true or it isn't. There is no room for a "Paradox" in mine or Analashok's work. Also, I don't think learning Fallout 3 scripting is a thing for beginners. Alot of functions do not work how they are suppose to. GECK isn't a very stable or suitable work atmosphere for scripting, either.

 

Translating code is a GOOD technique...Have you ever heard of Pseudocode?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...