STAR TREK 2d20
  1. #1
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    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
    returning pc or npc for sActorType

    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

  2. #2
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    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

  3. #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

  4. #4
    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

  5. #5
    In general, if defining new system, I suggest matching field locations in database between PC and NPC to save work later.

    Cheers,
    JPG

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    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!

  7. #7
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    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...

  8. #8
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    Quote Originally Posted by Trenloe View Post
    I told him it would be a good idea to reorganise the NPC database structure.

    He doesn't listen to me though...

    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.

  9. #9
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Quote Originally Posted by damned View Post
    ...your words of wisdom filtered thru to the conscious layer...
    Wasn't sure you had one of those!
    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!

  10. #10
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,649
    Blog Entries
    1
    Quote Originally Posted by Trenloe View Post
    Wasn't sure you had one of those!
    I have a conscious side - its just not very good at programming ok...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in