Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 ```If ConditionA = 1 AND ConditionB = 1 Then Effect1End IfIf ConditionC = 2 AND ConditionD = 2 Then Effect2End If```The above isn't working, and I'm beyond frustrated with it. For some reason, if the first If Then statement doesn't get run, the scripting language decides to skip **EVERYTHING** AFTER IT. >_<In this example (and it is purely an example, as I didn't want to post all my GetVar codes to make it even more confusing), if ConditionA and ConditionB aren't met, but ConditionC and ConditionD ARE met… Effect2 still does not happen. And this isn't a case of a syntax error -- though C and D were met, Effect2 still wasn't happening. So I met the conditions for A and B, and suddenly both Effect1 **AND** Effect2 happened.Is this really working as intended? Is there something I'm missing? Please tell me I don't have to do a few hundred nested If Then statements just to get my desired effect. x.x Link to comment Share on other sites More sharing options...
Owen F Posted September 2, 2009 Share Posted September 2, 2009 actually, thats because you don't need another if statement.Remove your first End if and Put ElseIf instead of the 2nd If.here we go:```If ConditionA = 1 AND ConditionB = 1 Then Effect1ElseIf ConditionC = 2 AND ConditionD = 2 Then Effect2End If``` Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 I was curious as to if ElseIf statements worked in EE's scripting, but hadn't had the patience to test it with anything I already had working. Thanks for confirming that for me. XDNonetheless, that's epic annoying for my brain, because according to my logic, it should just keep running down the list of If Then's. But then, it's been forever since I've touched code this much.DAMMIT COMPUTER, I GAVE YOU A CHECKLIST, NOW RUN THROUGH IT WITHOUT QUESTIONING ME! AND I SWEAR IF YOU DON'T DOUBLE-CHECK EACH AND EVERYONE I'M NEVER GOING TO PUT IN THAT NEW STICK OF RAM I'VE BEEN PROMISING FOR YEARS. Link to comment Share on other sites More sharing options...
Owen F Posted September 2, 2009 Share Posted September 2, 2009 @Synectics:> DAMMIT COMPUTER, I GAVE YOU A CHECKLIST, NOW RUN THROUGH IT WITHOUT QUESTIONING ME! AND I SWEAR IF YOU DON'T DOUBLE-CHECK EACH AND EVERYONE I'M NEVER GOING TO PUT IN THAT NEW STICK OF RAM I'VE BEEN PROMISING FOR YEARS.I lol'd–-It needs to know what to do if the 'if' is false xd hence, else or elseif Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 Back already. /sigh /shakefist@computerSo, here's the code simplified:```If NPC = 5 AND Condition1 = True Then Effect1ElseIf NPC = 5 AND Condition2 = True Then Effect2ElseIf NPC = 5 AND Condition3 = True Then Effect3End If```And once more, the same sort of deal. Effect2 is only happening if NPC = 5 AND Condition1 = True AND Condition2 = True, as opposed to what I obviously would like it to be doing.If I start off with just NPC = 5 and Condition2 = True, then Effect2 never happens. But as soon as I enable Condition1, Effect 1 happens, followed by Effect2. Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 Bleh, double-post, but needed to add:In the above example, if Condition3 is met, Effect3 still won't happen until BOTH Condition1 and Condition2 are met. Link to comment Share on other sites More sharing options...
Owen F Posted September 2, 2009 Share Posted September 2, 2009 try using End Ife.g```Effect 1End IfElseIf ``` Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 Small update. Tried the following:```If NPC = 5 Then If Condition1 = True Then Effect1 ElseIf Condition2 = True Then Effect2 ElseIf Condition3 = True Then Effect 3 End IfEnd If```But also to no avail.And adding End If seems like it'd close the If altogether, meaning ElseIf wouldn't work. But then, I would think If Then statements following one another should work…. >.> Trying it now. Link to comment Share on other sites More sharing options...
Bobosk Posted September 2, 2009 Share Posted September 2, 2009 I really hope you don't listen to him Synectics…Yes, ElseIf worksYes, It DOES run down the list of If's, when you have them like your first exampleNo, you do not need a Else/ElseIf when using If'sHis most recent post, will cause errors... Speaking of Errors, have you tried turning "Scripting Errors" on for your server? That might help you more than anything we have to say...Side note: Check the tutorials, they still help, even if you know this stuffHere's one for example: [http://www.touchofdeathforums.com/smf/index.php/topic,850.0.html](http://www.touchofdeathforums.com/smf/index.php/topic,850.0.html)Side Note#2: Syntax errors in GetVars cause scripts not to work, so you might as well just post the whole script here, otherwise, you're going to get alot more vague help Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 ```Sub OnNPCDeath(Index, Map, NPCNum, NPCIndex) If NPCNum = 5 Then Call BattleMsg(Index, "You killed a " & NPCNum & ".", BRIGHTRED, 0) If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "Part1") = 1 Then Call PlayerMsg(index, "Quest complete: Nate's Trainee. Return to Nate Issley.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "DummyHit", 1) End If If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "Part1") = 1 Then Call PlayerMsg(index, "Quest complete: Ivory's Trainee. Return to Ivory.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "DummyHit", 1) End If End IfEnd Sub```Been working on slimming down the code from what it was. This is what I have at the moment, copied over.When GetVar…QuestIvory = 1, nothing happens. But if both GetVar...QuestNateIssley and GetVar...QuestIvory = 1, then it will run both, one after the other.EDIT: In fact, I just moved the BattleMsg down below the GetVar If's, but before the last End If, like so:```Sub OnNPCDeath(Index, Map, NPCNum, NPCIndex) 'Call BattleMsg(Index, "You killed a " & NPCNum & ".", BRIGHTRED, 0) If NPCNum = 5 Then If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "Part1") = 1 Then Call PlayerMsg(index, "Quest complete: Nate's Trainee. Return to Nate Issley.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "DummyHit", 1) End If If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "Part1") = 1 Then Call PlayerMsg(index, "Quest complete: Ivory's Trainee. Return to Ivory.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "DummyHit", 1) End If Call BattleMsg(Index, "You killed a " & NPCNum & ".", BRIGHTRED, 0) End IfEnd Sub```Therefore, if it were going all the way down the list despite the conditions not being met, the BattleMsg should still be called. Problem is, it's not getting called at all. Even though the If statements above it don't get run, it should still get called, amirite? Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 Yeah. It's still broken. Now I've tried:```If NPCNum = 5 Then If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "Part1") = 1 Then Call PlayerMsg(index, "Quest complete: Nate's Trainee. Return to Nate Issley.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "DummyHit", 1) End If If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "Part1") = 1 Then Call PlayerMsg(index, "Quest complete: Ivory's Trainee. Return to Ivory.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "DummyHit", 1) End IfEnd IfCall BattleMsg(Index, "You killed a " & NPCNum & ".", BRIGHTRED, 0)```And get this: the BattleMsg will **only** get called if:a) The NPC is NOT 5b) The two If Then statements inside of If NPCNum = 5 are both trueWTF. Link to comment Share on other sites More sharing options...
Bobosk Posted September 2, 2009 Share Posted September 2, 2009 Yes, you are, however when this is the case, it's generally because of Syntax errors…Specifically in your case. When you use GetVar() it returns it as a string... SO you need to convert your string to another type of something.. For your script, i'd use Int()```Sub OnNPCDeath(Index, Map, NPCNum, NPCIndex) If NPCNum = 5 Then Call BattleMsg(Index, "You killed a " & NPCNum & ".", BRIGHTRED, 0) If Int(GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "Part1")) = 1 Then Call PlayerMsg(index, "Quest complete: Nate's Trainee. Return to Nate Issley.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "DummyHit", 1) End If If Int(GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "Part1")) = 1 Then Call PlayerMsg(index, "Quest complete: Ivory's Trainee. Return to Ivory.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "DummyHit", 1) End If End IfEnd Sub``` Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 Even with the exact code you just gave, it's still not working.Using your version, the Battlemsg gets called, but again, if IvoryQuest is 1 and NateIssely isn't, IvoryQuest's effect doesn't get called.I even tried placing a BattleMsg at the end of the code – outside of the If NPCNum = 5 -- and it won't get called if both If's above aren't true... and it SHOULD. If you kill NPC 5, and neither quest code is true, it should keep on going to the bottom of the Sub and call the Battlemsg.And again, if BOTH quest conditions are true, BOTH get called.Out of the few hundred lines of code I've placed, including a LOT of custom menu code and LOTS of If Then statements one after the other, such as in the Sub MenuScripts, I've never had anything like this happen. Definitely the most frustrating thing I've ever had happen with code. Link to comment Share on other sites More sharing options...
balliztik1 Posted September 2, 2009 Share Posted September 2, 2009 It's actually not as complicated as it seems. It's just a common misconception about GetVar. GetVar returns a _String_ value. You are comparing it to a numeric value. VB converts most values automatically, but if the variable is not set (i.e ""), there is no numeric counterpart for that. The result is an RTE 13, type mismatch, which effectively breaks the script.It's a really easy fix. This will work:```Sub OnNPCDeath(Index, Map, NPCNum, NPCIndex) If NPCNum = 5 Then If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "Part1") = "1" Then Call PlayerMsg(index, "Quest complete: Nate's Trainee. Return to Nate Issley.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestNateIssley", "DummyHit", 1) End If If GetVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "Part1") = "1" Then Call PlayerMsg(index, "Quest complete: Ivory's Trainee. Return to Ivory.", BrightGreen) Call PutVar("Scripts\Charextras\" & GetPlayerName(index) & ".ini", "QuestIvory", "DummyHit", 1) End If End If Call BattleMsg(Index, "You killed a " & GetNPCName(NPCNum) & ".", BRIGHTRED, 0)End Sub```If you'll notice, the only thing I did was put quotation marks around the 1 that you were comparing the GetVar to. This is all it takes.Oh, I lied. I also added a GetNPCName to your BattleMsg. Doesn't make sense for a player to get a message like "You killed a 5." ;) Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 Aight, about to try this.And don't worry, that Battlemsg isn't meant for the player – it was meant for my debugging purposes, to make sure the NPC I was killing really was, indeed, number 5\. XD Link to comment Share on other sites More sharing options...
Synectics Posted September 2, 2009 Author Share Posted September 2, 2009 Oh for the love of gawd, it's finally ing working now. I can finally move on to bigger and better things!!!!Thank you very much for that brief explanation, too. It's so frustrating to know what I want and need to do, but not understand the HOW part./tip of the hat @ all who helped! Link to comment Share on other sites More sharing options...
balliztik1 Posted September 2, 2009 Share Posted September 2, 2009 No problem.Just remember, kids: GetVars are striiiiiiiiiiiings! *flies off into sky* Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now