Launch different dialogues [Defold + Arcweave + DefArc] (solved)

Ok, so there are two approaches - you can either handle such logic in Lua script in Defold or try to use as much of Arcweave as possible:

1. Defold + Lua approach

You can for example create a table with data for each NPC - holding some flags, like conversation_x_happened or reached_y_node or more descriptive bob_insulted_mark_in_tavern. Then, before showing any text from DefArc - check those flags. Format of such table might be however you want - you can include here information about which node in Arcweave JSON it regards or which title in Node it regards. This actually might be easier, because you then describe the nodes in Arcweave with the same names as in Lua table, for example: Fiend starts or Fiend Attacks! and in Arcweave:

You can also utilize here components for checking events (Like I do above, where you notice the icons for events)

For randomness - perhaps you could name some of the starting nodes start_node_x and x would be a number, so in Defold you can generate this random in runtime, when you start a conversation with given NPC. Implementation is here written directly by you and you have full control over it and you only utilize DefArc, for getting text (and options) for elements you choose.

Notice DefArc allows you to choose elements not only by id, but also by a title of an element!
Take a look at API for e.g. get_text():


2. Arcweave approach

I think doing as much of the logic as possible in Arcweave is better, because you can then test it in Arcweave too - using directly the Play button there! Especially for your use cases.

DefArc comes with the example utilizing directly Sample Project from Arcweave. In this project there is a usage of variables shown - take a look at this node with an ArcScript:

This ArcScript is automatically parsed by DefArc in get_text() function - it will create such variable inside DefArc and if there will be any ArcScript detected later on and it will be parsing such variable - it will have this variable’s value already saved and will compare it then to give you a proper result.

In the SampleProject, when reaching node The small house - Examine the painting - the variable paintingExamined is created inside DefArc table and it’s value is stored there (in this case true). So after this node you will have a table in defarc.global_variables:

DEBUG:SCRIPT: 
{ --[[0x7f0580153330]]
  paintingExamined = true
}

(I added pprint(M.global_variables) inside DefArc’s M.save_variable_function())
Check out how it is happening automatically:

Peek 2022-11-11 16-33


Later on, in the Arcweave’s Sample Project you see the Condition:

It is also automatically checked in defarc.get_options_table()
If condition in the ArcScript is not met, the option that is linked to it, will not be in the options_table. Otherwise, it will be there! :wink:

You can check out the conversation with the Knight, before examining the picture and after it (when new option will be available [You remember the name on the painting] ):

DefArc currently have 2 crucial parsers for ArcScript (check out the source code for those functions:)

local function arcscript_if_parser(splitted, start_at) - for parsing ArcScript if else conditions

local function arcscript_assingment_parser(splitted, start_at) - for assigning values to variables

There is a function in ArcScript for generating random value - but sadly, it is not yet implemented in the DefArc :frowning: If you would like it, you can modify the function:

function M.arcscript_code_parser(splitted, start_at)
    local next = splitted[start_at + 1]
    local next_len = string_len(next)

    if string_find(next, "elseif") then
	    next = string_sub(next, 7, next_len)

    elseif string_find(next, "endif") then
	    splitted[start_at] = ""			-- remove code opening tag
	    splitted[start_at + 1] = ""		-- remove endif tag
	    splitted[start_at + 2] = ""		-- remove code closing tag

    elseif string_find(next, "if") then	arcscript_if_parser(splitted, start_at)
    elseif string_find(next, "= ") then	arcscript_assingment_parser(splitted, start_at)
        -- Add here :
        -- elseif string_find(next, "random") then arcscript_random_parser(splitted, start_at)
    end
end

And write a function arcscript_random_parser analogically to other parsers, that will assign a random value (for example using Defold’s math.random())

More about ArcScript:


A hint for the future:

I use Defold Printer by @Insality to print the text in my game instead of just putting the text using gui.set_text() (so in the first image you can notice Printer’s specific tags {strong} Text here {/} :wink:

9 Likes