Building a game in Core Engine ( Day 6 )

Grimland
4 min readJul 28, 2020

--

Here we are on Day 6 and i’m convinced that i can get this Quest Giver thing working. I have the Quest Window built and the Quest Giver has a trigger, now we need to make the Trigger do something in the script.

by browsing the API i find this bit of code and figure it should help with what i’m trying to do.

I’m going to use this and see if i can print something to the client and then try to set Visibility = True for my UI

Do i get an error … No .. do i see anything print when press F on my Quest Giver trigger … nadda. Progress but no progress.

[ Update ] : i didn’t call the function so it did .. nothing as expected

New code worked once and then broke when i ran it again .. odd

Working Code for Quest Window

OK enough of this … let’s start from scratch. Opened a new project and did the folowing:

  • Add Human
  • Add Trigger ( Check box for Interactive )
  • Create Group (Questline) and drag both in
  • Create Group (Quest)
  • Create UI Panel with a Child UI Text
  • Rename panel to “QuestWindow”
  • Change visibility to Force_OFF

TEST RUN GAME — SUCCESS

Create Script ( Child of Trigger ) with this code

TEST RUN GAME — ERROR

Error running Lua task: [B29D4017593D5CC8] OpenQuest:4: Attempted to modify a field on a non-networked object. (Try marking the object as Networked or move it into a Client Context or Server Context to fix this problem.) Field: isInteractable, Object: Trigger

Right Click QuestLine group and Create Network Context → New Client Content Containing This. Now drag the Quest Group into the new Questline network object.

The reason we choose Client Context is because we only want the player to see the Quest Window and nobody else.

TEST RUN GAME —SUCCESS

Quest Window shows now.

Quest Window Popup

Now we can work on Adding buttons so we can Accept/Decline the quest and when quest is complete, a Reward button. But before we can touch the buttons we need to put focus on the Cursor somehow.

Found these while search the Discord ( could not find cursor in the API for some reason )

UI.IsCursorVisible(true)
UI.IsCursorVisible(false)
UI.CanCursorInteractWithUI(true)
UI.CanCursorInteractWithUI(false)
UI.SetCanCursorInteractWithUI(true)
UI.SetCanCursorInteractWithUI(false)

Found the cursor/mouse items in UI section of API ( https://docs.coregames.com/core_api/ ) and search Cursor it’s close to the bottom of the page.

Either way here is the new code and it works just fine.

Quest Window code with working cursor

Next step will be the Decline button so that we can close the UI Window. After some digging i think we need to use:

clickedEvent

After referencing the API i saw that i needed to create reference to the button and trigger an event, so i went looking for examples and after many many NIL errors i started to get somewhere. This code was working as long as i gave the Decline Button a script … dirty but it works

Wouldn’t it be nice to merge both into one script, so off we went to try that … well we saw more and more errors as i tried different scenarios. After asking a few questions in Discord i was advised that these two lines of code could not coexist in the same world, so one had to go.

Eventually we got to the point where i was able to reference the Button via the similar FindObjectByName method and we’re back in race !!

Here we are with a working script that allows us to do the following:

  • Walk up to Quest Giver and press ‘ F ‘ to interract
  • Quest Window opens
  • Accept Button prints a message in Event Log and closes Quest Window
  • Decline Button closes Quest Window
Well document script for Quest Line

Now that we have a well documented script and a next step ( Activating Quest / Quest Log ui ), i can officially say we made great progress today .. with a little help.

[ UPDATE ] It seems after i code the ELSE section it kept giving Accepted Quest printout only so had to adjust the OnClicked function a bit

Correction to OnClicked function

--

--