Skip to content

Cannot get NUI Label to show up in a new window *fixed*

aksyomaksyom Member Posts: 1
edited June 2022 in Builders - Scripting
So, I just wanted to test the NUI feature, and I made this very simple script that I hooked up with the module OnRest event.
#include "nw_inc_nui"

void main() {
    if (GetLastRestEventType() != REST_EVENTTYPE_REST_STARTED)
        return;
    object pc = GetLastPCRested();
    json col_list = JsonArray();
    JsonArrayInsert(col_list, NuiLabel(JsonString("test text 1"), JsonInt(0), JsonInt(0)));
    json root = NuiCol(col_list);
    json window = NuiWindow(root, JsonString("test title"), NuiRect(-1.0f, -1.0f, 450.0f, 320.0f), JsonBool(FALSE), JsonBool(FALSE), JsonBool(TRUE), JsonBool(FALSE), JsonBool(TRUE));
    int token = NuiCreate(pc, window, "KCRS_TEST");
    WriteTimestampedLogEntry(GetName(pc) + " chat event, token = " + IntToString(token));
}

When I rest the player, a Window with title "test title" does show up BUT in there is no label in the window. The window is completely empty, as if the NuiLabel is somehow "hidden" or something?

Can somebody who knows about NUI explain to me what am I doing wrong?

I am running the module I am working on in an NWNX linux server. But I don't think that matters ... or does it?

EDIT: I FIXED IT, the problem was that I was not using the JsonArrayInsert properly. JsonArrayInsert RETURNS the modified array! And thus I just needed to set the array with the return value as thus:
col_list = JsonArrayInsert(col_list, NuiLabel(JsonString("test text 1"), JsonInt(0), JsonInt(0)));

So it was my fault for not reading the documentation. Anyway, problem solved.

I just leave this message here so that others who might come up with this problem can see the solution.
Post edited by aksyom on
Sign In or Register to comment.