morogoth35 Posted April 7, 2017 Share Posted April 7, 2017 I have a bookshelve in Skyrim that I want to have a messagebox displayed when it's activated. The crux here is that the bookshelve has doors that opens when activated to reveal the bookshelf. So I put the script on the doors. What happened was that I got the messagebox when I opened the door to the bookshelve but when I close it I get the same message. So I want to make the script reset itself after the container has been activated only once. Here is my working script that has this issue with it displaying the message when opening and closing the door. Event OnActivate(Objectreference akActionref)Debug.MessageBox("Lengthy Books Are Stored Here")EndEvent So I tested a new script that would reset itself when it has been activated once. So I tried doing this: int count Event OnActivate(Objectreference akActionref)int count == + 1 if count == 1Debug.MessageBox("Lengthy Books Are Stored Here") elseif count == 2 Reset count endifEndEvent That script doesn't work. How do you reset an integer? Link to comment Share on other sites More sharing options...
KunoMochi Posted April 7, 2017 Share Posted April 7, 2017 First, you don't need to re-declare 'count' in OnActivate if it is already declared in the script prior. You should also initialize it to 0 ('int count = 0') to start. Second, 'count == + 1' isn't a valid statement. If you are trying to increment it by 1, it should be 'count = count + 1'. Third, for the second IF/ELSEIF condition, I would recommend using 'count > 1' to cover if the value somehow goes over 2. Last, if you are using 'Reset count' to make it reset back to 0, just set 'count = 0'. Link to comment Share on other sites More sharing options...
morogoth35 Posted April 7, 2017 Author Share Posted April 7, 2017 int count Event OnActivate(Objectreference akActionref) count = count + 1 if count == 1 Debug.MessageBox("Lengthy Books Are Stored Here") elseif count > 1 Count = 0 endif EndEvent Is this correct? Link to comment Share on other sites More sharing options...
KunoMochi Posted April 7, 2017 Share Posted April 7, 2017 You forgot to initialize 'int count = 0'. It might already be set to 0 at start but it is good habit to have it set to a value after you declare it. Link to comment Share on other sites More sharing options...
morogoth35 Posted April 7, 2017 Author Share Posted April 7, 2017 You forgot to initialize 'int count = 0'. It might already be set to 0 at start but it is good habit to have it set to a value after you declare it.I got it working the exact way I wanted to with this script: int count Event OnActivate(Objectreference akActionref)count = count + 1 if count == 1Debug.MessageBox("Lengthy Books Are Stored Here") elseif count > 1Count = 0 endifEndEvent Link to comment Share on other sites More sharing options...
morogoth35 Posted April 7, 2017 Author Share Posted April 7, 2017 And thanks for your help! I appreciate it! Link to comment Share on other sites More sharing options...
foamyesque Posted April 7, 2017 Share Posted April 7, 2017 I wouldn't even bother with an integer. There's a number of possible solutions. The simplest is using a bool, and have it toggle to true or false depending on whether the doors are open or closed (i.e each onActivate event will flip it), and use that as a condition for your message box. If more complex stuff needed to be done, a state-based solution would be a better call. You've also got numerous syntax problems. " == " and related items (e.g. " >=, >, <, <=, !=") are logical comparisons, generally used with either "if" statements or "while" statements. They will not assign values to a variable. You can only declare a variable ("int count", for example) once; you have two attempts at it, and the second will conflict. You also cannot use a variable inside its own declaration ("int count = count" will fail, and is logically incoherent anyway). If the second was meant to be an increment, you want either "count = count + 1", or, more compactly, "count += 1", which is equivalent. ints do not have a Reset function, as such; you'd have to code one personally but there's usually no point, since all it would be doing would be providing an alias of some sort for a direct variable assignment (e.g. "count = 0" or "count = defaultValue", or whatever). If you DID have some kind of custom Reset function, the syntax for it would be along the lines of "Reset(count)", not "Reset count" as you have it. .... this post probably obsoleted by replies made while composing it :v Link to comment Share on other sites More sharing options...
Recommended Posts