[QUES] Return value from new Notification

Is it possible to get a return value from a Notification without using the addEvent.

i.e. I want to have the player make a decision without it being registered as an event.

Not really but you can schedule an event to fire immediately. The reason why you have to do it via addEvent is that the player might save the game and quit while the event is on screen. When reloading the game the event will still be displayed and the only way the system knows how to notify the result is because it was registered via addEvent with a unique id before. Hope this makes sense.

another trick is to add the event via addEvent but not to have any triggers on it and then to trigger it manually by pushing the notification itself to GameManager.company.notifications

This way, you can dynamically trigger an event at any given time and the callback will still work.

Ahh, okay I think I’m understanding correctly. Would I do something like:,

GameManager.company.notifications.push(new Notification({sourceId: eventId});

And then have the corresponding event id contain the rest of the event?

yes, that’s it :slight_smile:

Wow. Only spent the last hour trying to come up with that one. Staring me right in the face.
Thanks :smile:

I would keep the Notification and event defined in one object though, so it will be like:

GameManager.company.notifications.push(myEvent.getNotification());

So I tried that but it doesn’t seem to call the “complete” function after the options have been displayed.
I’m probably doing something wrong but could you elaborate a little please :smile:

1 Like

probably best if you post the code somewhere… as long as the id’s match up and you add the event via addEvent this should work.

    Example.EventCaller = function () {  // Using an event key to call this.
		GameManager.company.notifications.push(myEvent.getNotification());
    };


Example.addEventNew = function() {
        var eventId = "myEvent-id";
        var myEvent = {
            id: eventId ,
            isRandom: false,
            maxTriggers: 1,
            trigger: null,
            getNotification: function (company) {
                    //blah blah blah
                    return new Notification({
                    sourceId: eventId,
                    header: "Header".localize(),
                    text: message,
                    options: ["One", "Two"]
                });

},
            complete: function (decision) {
                  return new Notification("Test", "Test.");
                    }

            }
        };

        GDT.addEvent(myEvent);
    };

Okay this is how I think it should be but it doesn’t seem to work at at all.

Just some example code to make it easier to read etc.

It’s this bit I am not sure what to call “myEvent.getNotification()”

well, the myEvent object is defined in a different scope then what you try to access when adding the notification. Otherwise it looks fine.

If you move the definition out, it should work:

(function(){
	var eventId = "myEvent-id";
			var myEvent = {
				id: eventId ,
				isRandom: false,
				maxTriggers: 1,
				trigger: null,
				getNotification: function (company) {
						//blah blah blah
						return new Notification({
						sourceId: eventId,
						header: "Header".localize(),
						text: message,
						options: ["One", "Two"]
					});

	},
				complete: function (decision) {
					  return new Notification("Test", "Test.");
						}

				}
			};

	Example.EventCaller = function () {  // Using an event key to call this.
			GameManager.company.notifications.push(myEvent.getNotification(GameManager.company));
		};
		

	Example.addEventNew = function() {
			GDT.addEvent(myEvent);
		};
})();

also, since the getNotification() event expects a company object, you should pass this in when calling the method.

Ahh okay, this works great, I tried it via the trigger method just using a bool and the dataStorage which also worked.

I do have one more question for you if I may.

I want to pass some values from “getNotification” to “complete”. For example if I randomly choose a staff member in “getNotification”

With:

GameManager.company.staff.skip(1).pickRandom();

How would I then make sure I am selecting the same staff member in complete?

I have tried to do it via the dataStore by getting the index of the staff member saving it there then attempting to use that to access it again in “complete” but I have been unsuccessful in my implementation of that xD

you are on the right track. usually you would simply remember the id of the staff member in your data store and then use this to look up the staff member.

Something like var selectedStaff = GameManager.company.staff.first(function(staff){return staff.id == id;}); where the id would be the one that you remembered in the data store.

Hmm, I keep getting “Can’t fine child array” when we get to “complete”

getNotification:

var staffMember = GameManager.company.staff.skip(1).pickRandom();
GDT.getDataStore("RoleImp").data.bostaffMember = staffMember.id;

complete:

var nullme = GDT.getDataStore("RoleImp").data.bostaffMember;
var selectedStaff = GameManager.company.staff.first(function(staff){return staff.id == nullme;});

Where have I gone wrong here? :stuck_out_tongue:
Thanks again.

Umm nevermind, that works. I was trying to call “GDT.off” in “complete” I moved it too the eventHandler method and it works fine now :slight_smile:

1 Like