LocalVar and if-statements - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: LocalVar and if-statements (/thread-19339.html) |
LocalVar and if-statements - i3670 - 11-24-2012 As you can read in the script. If all the machines are running the player can use the item on the area but if only 4 or less are you can't. I thought this script would work but it will not. void OnStart() { for(int i=1;i<=6;i++){ AddUseItemCallback("UsingOrbPieces", "orb_piece_"+i+"", "AreaUseOrbPiece","UseOrbPiecesOnArea", false); } } ///Using the orb pieces/// void UseOrbPiecesOnArea(string &in asItem, string &in asEntity) { if(GetLocalVarInt("AllMachineryUpAndRunning") == 5) { RemoveItem(asItem); AddLocalVarInt("OrbPutTogether", 1); OrbAllDoneLocal(); } else if(GetLocalVarInt("AllMachineryUpAndRunning") == 0 && GetLocalVarInt("AllMachineryUpAndRunning") == 1 && GetLocalVarInt("AllMachineryUpAndRunning") == 2 && GetLocalVarInt("AllMachineryUpAndRunning") == 3 && GetLocalVarInt("AllMachineryUpAndRunning") == 4) { SetMessage("Descriptions", "Hint_15", 3.0f); PlaySoundAtEntity("", "27_thump.snt", "Player", 0.1f, true); } } RE: LocalVar and if-statements - The chaser - 11-25-2012 The message appears screwed up, i3670. I can't read the script. RE: LocalVar and if-statements - i3670 - 11-25-2012 screwed up how? RE: LocalVar and if-statements - The chaser - 11-25-2012 It appears like: void OnStart() { for(int i=1;i<=6;i++){ AddUseItemCallback("UsingOrbPieces", "orb_piece_"+i+"", "AreaUseOrbPiece","UseOrbPiecesOnArea", false); } } ///Using the orb pieces/// void UseOrbPiecesOnArea(string &in asItem, string &in asEntity) { if(GetLocalVarInt("AllMachineryUpAndRunning") == 5) { RemoveItem(asItem); AddLocalVarInt("OrbPutTogether", 1); OrbAllDoneLocal(); } else if(GetLocalVarInt("AllMachineryUpAndRunning") == 0 && GetLocalVarInt("AllMachineryUpAndRunning") == 1 && GetLocalVarInt("AllMachineryUpAndRunning") == 2 && GetLocalVarInt("AllMachineryUpAndRunning") == 3 && GetLocalVarInt("AllMachineryUpAndRunning") == 4) { SetMessage("Descriptions", "Hint_15", 3.0f); PlaySoundAtEntity("", "27_thump.snt", "Player", 0.1f, true); } } Wait... what the heck? Anyway, you have a bigger script, right? If you have more from this machine, you should post it. Maybe the issue is somewhere else. RE: LocalVar and if-statements - i3670 - 11-25-2012 Of course I have a bigger script but, I don't know if I feel like posting 250 lines of code when most of it is irrelevant to this part of the script. RE: LocalVar and if-statements - Your Computer - 11-25-2012 Do you realize that AllMachineryUpAndRunning can't be different numbers at the same time? So even though AllMachineryUpAndRunning doesn't equal 5, the else-if will never evaluate to true. Also, it may be necessary to know how AllMachineryUpAndRunning is incremented. RE: LocalVar and if-statements - i3670 - 11-25-2012 Yes I do realize that the Local can't be different numbers at the same time but since I don't know how many machines the player has activated I did it like that and I do realize that those GetLocals are the problem, but how am I suppose to know how many the player has activated? Edit: Shall I perhaps split it up so else if Getlocal ==1 else if Getlocal ==2 RE: LocalVar and if-statements - Your Computer - 11-25-2012 You used && in your else-if statement. That's like saying, if AllMachineryUpAndRunning equals 0 AND equals 1 AND equals 2, etc, do this. If you used ||, then it would be like saying, if AllMachineryUpAndRunning equals 0 OR equals 1 OR equals 2, etc. RE: LocalVar and if-statements - i3670 - 11-25-2012 Understood, changed, worked. Thank you YC. |