Author Topic: array of object inside objective  (Read 109 times)

ninekorn

  • Full Member
  • ***
  • Posts: 168
    • View Profile
array of object inside objective
« on: May 09, 2019, 09:48:14 pm »
Hi,

I need some help trying to put an array of objects inside of an objective? Is it possible and if it is, how do I do it?

On the official wiki page it shows this: "npc.AddObjective(25334, "go_to_jumpgate", {jumpgate_id: 15});"

But if I put and array of objects instead inside the "object parameter", it gives me the error below?




Does anyone have any ideas?

nine

ninekorn

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: array of object inside objective
« Reply #1 on: May 10, 2019, 02:46:35 pm »
The AI of the npcs (the scripts that contains function Decision(args)) are Global. All Global variables are shared with all of my NPC Drones. This means I couldnt use global variables  to reset functions and any other settings in side the script without resetting ALL of my NPC drones at the same time.

I found a solution.

Since the variables are global for NPCs that share the same AI scripts (and this Global feature is is kinda cool), and since I have a maximum of 5 drones at the same time, i just initialize an array containing 5 length... The arrays are accessible by the formation position that is assigned to the Global variable linked to the NPC ID at their creation. I am then able to get the EXACT variable linked to the drone from the arrays that were initialized once.

Code: [Select]
    if (initStartingStuff == 1)
    {
        player_id = npc.GetTag(SHIP_ID, "ownerPlayerShipId");

        for (var i = 0; i < 5; i++) {
            lastDistanceToWaypoint.push(0);
            lastDistanceToWaypointAdjacentFB.push(0);
            lastDistanceToWaypointOppositeRL.push(0);


            lastSpeedNPC.push(0);
            lastSpeedPlayer.push(0);

            frontPushCounter.push(0);
            backPushCounter.push(0);
            leftPushCounter.push(0);
            rightPushCounter.push(0);

            lastFrontPushCounter.push(0);
            lastBackPushCounter.push(0);
            lastLeftPushCounter.push(0);
            lastRightPushCounter.push(0);

            lastSomeOtherRLDOT.push(0);
            lastSomeOtherFBDOT.push(0);
            lastSomeOtherRLDOTTWO.push(0);

            pushLEFT.push(0);
            pushRIGHT.push(0);
            pushBACK.push(0);
            pushFRONT.push(0);

            formationSwitches.push(1);
            mainSwitches.push(0);

            selectedTarget.push(-1);
            lockSwitches.push(0);
            lockBattlePositionSwitches.push({ x: null, y: null });
            lockBattlePositionSpeedValueSwitch.push(7);
            lockLastBattleDOTDirectionValueSwitch.push(0);

        }
        initStartingStuff = 0;
    }


In order to reproduce this Global "issue" in the AI script, it's super easy... You create an AI script that is used by a couple NPCs, you add +1 to the variable at each frames... And then you debug in the console the variable... You will notice that ALL AI's have the exact SAME value and they are just making the value get bigger, faster, even IF the AI's were initialized at a different time, they still have the same counting value as the other NPC AI's...

For instance, let's say the NPC1 was spawned and it's value is Now at 1000...You spawn a second NPC, named NPC2 that is created 1 minute later so "normally" it would be supposed to have the counting value at 0 because it was just initialized, but the counting value is actually 1000 instead of 0... and after that, you have TWO drones that are increasing the value +1 each frames so the value increases twice as fast.




Maybe it was meant to be this way in Void Expanse, maybe it doesn't, but personally, I like it.

nine
« Last Edit: May 10, 2019, 02:56:51 pm by ninekorn »

ninekorn

  • Full Member
  • ***
  • Posts: 168
    • View Profile
Re: array of object inside objective
« Reply #2 on: May 12, 2019, 03:32:44 pm »
nevermind... this solution wont work for multiplayer as other player`s drones will crunch the data in the arrays that were setup on the player before them... I will try to find another solution. By the way? is there a way to modify the data inside of an objective without having to recreate the objective?

I guess my only solution at this point might be to use the Global variables otherwise the new drone scripts won`t work in multiplayer.
« Last Edit: May 12, 2019, 04:20:00 pm by ninekorn »