Thread: Working with then and else...
-
September 16th, 2014, 01:33 #1
Working with then and else...
Im having trouble extending my INIT rolls.
Together with Trenloe we scripted the action for the NPCs.
Now I need to take that code and check whether it was a PC or an NPC that rolled and then update a different database field depending on who did it...
This function checks where the INIT roll came from:
Code:function getSkillRoll(rActor, vSkill) local rRoll = {}; rRoll.sType = "init"; rRoll.aDice = { "d10","d10" }; local sInit = DB.getValue(vSkill, "Speed", ""); Debug.console("sInit:" .. sInit); local sActorType, nodeActor = ActorManager.getTypeAndNode(rActor); Debug.console("nodeActor: " .. nodeActor); Debug.console("sActorType: " .. sActorType); rRoll.sDesc = "[INIT] " .. DB.getValue(vSkill, "value", ""); return rRoll; end
In the case of npc I need to update the npc.init database field (which works) but I cant work out the right syntax to check if its a PC or a NPC rolling and in the case of PC update the char.init field instead...
Code:function onRoll(rSource, rTarget, rRoll) local rMessage = ActionsManager.createActionMessage(rSource, rRoll); -- Get the total of the roll - this includes and modifiers local sRollTotal = ActionsManager.total(rRoll); -- Get the actor type and the database node of that actor (the record that made the roll). local sActorType, nodeActor = ActorManager.getTypeAndNode(rSource); -- If we have a valid actor database node: if nodeActor then --Get the npc init node and set the total value local npcInitDBNode = nodeActor.getChild("npc.init"); npcInitDBNode.setValue(sRollTotal); end rMessage.text = rMessage.text .. " " .. sRollTotal; Comm.deliverChatMessage(rMessage); end
-
September 16th, 2014, 01:37 #2
funny thing is... after typing this out and looking in the db.xml I could see that my code was still writing npc.init back to character xml - so as a quick fix I changed my PC init db field to also be npc.init instead of char.init and that works... but I would still love some help on how to write me if/then/else statements
-
September 16th, 2014, 02:17 #3
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,922
if op == "+" then
r = a + b
elseif op == "-" then
r = a - b
elseif op == "*" then
r = a*b
elseif op == "/" then
r = a/b
else
error("invalid operation")
end
-
September 16th, 2014, 02:19 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,612
Typing from phone so limited formatting.
if nodeActor then
if sActorType == "pc" then
DB.setValue(nodeActor, "char.init", "number", sRollTotal);
else
DB.setValue(nodeActor, "npc.init", "number", sRollTotal);
end
end
Cheers,
JPG
-
September 16th, 2014, 02:20 #5
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,612
In general, if defining new system, I suggest matching field locations in database between PC and NPC to save work later.
Cheers,
JPG
-
September 16th, 2014, 02:31 #6
I told him it would be a good idea to reorganise the NPC database structure.
He doesn't listen to me though...
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
September 16th, 2014, 02:34 #7
it is a brand new system... it makes much more sense leaving them the same.....
thanks andraax I couldnt get that working - it always kept telling me that first line needed to be: if op then - it didnt want any operators on the first line...
thanks moon_wizard - i think i was using the wrong variable on the nested if statements...
-
September 16th, 2014, 02:41 #8
i listen to you - i just dont always understand what you are saying when you say it...
as you can see above in post 2 your words of wisdom filtered thru to the conscious layer and i made the change....
ive just tested JPGs suggestion which also works but I think i should go with the simplified data structure.
-
September 16th, 2014, 02:55 #9Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
September 16th, 2014, 03:47 #10
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks