Is there a way to make it so the “template” modifies an HTML element based on what is entered in the Example.AddCustomItem function?
Yeah you can do something like this:
https://jsfiddle.net/rf9219wj/5/
var Example = {};
(function () {
var itemList = [];
Example.AddCustomItem = function(item){
//do something.. example:
var div = $("body");
div.append('<div id="example div">Id: ' + item.id + '</br>'
+ 'Name: ' + item.name + '</br>'
+ 'Category: ' + item.category + '</br>'
+ '</div>');
itemList.push(item);
}
var runCode = function(){
Example.AddCustomItem({
id : "MultiPlatformOptimized",
name : "Multi-Platform optimized",
category: "Level Design"
});
}
runCode();
})();
Thank you so much! I feel so stupid for not being able to do what seems so easy now that you’ve explained it.
You’re welcome,
Glad I could help
The key thing to adding / modifying the UI is not adding the elements to the DOM it’s making them visible when you want them to be visible. For example the code now will add a new div to the body, but that div will always be there even on the startup screen ect…
You’ll need to add components that are invisible to start with something like css: display:none, after that you’ll need to hook a function that will make your div visible. For example cheatmod adds an invisible div containing the cheat menu to the body on start up. Then I hook the GDT context menu and add my cheatbutton, when that button is pressed the cheatmenu div is put to visible.
Yeah, I’ve been using a mixture of .hide() and .show() and .toggle() after I append it once.
What are you working on if you don’t mind me asking?
It’s far from done. Addtionally, I started with practically no JS knowledge (I have been teaching myself since the beginning), so don’t be startled by incredibly bad JS coding.
That link in the thread is also old. I have changed a lot of the code since I moved over to Atom.
Looks cool, I did a bit of AI for competitorMod fun stuf.
If its something you can Decrypt the code for the UltimateLib, this can bring the new life.
So I have come across another thing that is beyond my substandard jQ and JS knowledge. I do not wish to give away what I am working, so I will try to provide a sufficient example.
My template looks like this:
var exampleTemplate = function() {
example.AddNew({
foo1: 'Hello!',
fooThing: 'John Smith',
fooDate: '1/2/3'
});
}
exampleTemplate();
Basically, I am attempting to add something like the below piece of code to my template:
trigger: function() {
GameManager.company.currentLevel == 1;
}
How would one push or “trigger” exampleTemplate();
based on what is entered into the trigger:
I have tried elsewhere to do something like:
if (foo.trigger && foo.trigger()) {
// Here I push foo
}
Any ideas?
if (foo.trigger && foo.trigger()) {
// Here I push foo
}
looks fine (if it’s in the addNew method.
try replacing the trigger method:
trigger: function() {
return GameManager.company.currentLevel == 1;
}
Does anyone know how to implement save-specific data? Specifically, how can I save whether or not a div is shown through save-specific data. I’ve messed around with DataStore, and it just doesn’t seem to work for me.
In a mod I am creating, various divs are appended (I show/hide all the main divs). I need to make it so that a div that is appended in one save wouldn’t be available in separate save or new game.
GDT.getDataStore(“modname”).data is used to save save-specific data. However, from what I understand, you’re trying to save data which you want to recall in other saves, in which case you’re better off using GDT.getDataStore(“modname”).settings.
Hello everyone,
I am johnwiliam I am new for this site and this is my first post here, hope all are doing well to sharing information here with others
Trust me, I’ve read the wiki; however, I just can’t seem to get DataStore to work correctly. And it does need to be save-specific, so .settings
is not what I need.
How exactly does GDT.fire
work? I have read the wiki, but I don’t fully understand it. An example would be awesome.
I suppose you want a custom event?
The way the event system works is, you add a callback function to a ‘key’.(with the GDT.on function) after that everytime you fire that event the code will be run so to add a new event you just do something like this:
var MODGLOBALSCOPEVARIABLE = {};
MODGLOBALSCOPEVARIABLE.eventKeys = {
globalEvents: {
testEvent1: 'modname.global.testEvent1',
testEvent2: 'modname.global.testEvent2'
},otherevents: {
testEvent3: 'modname.otherevents.testEvent3'
}
}
Then you add your listeners and methods:
var testFunc = function(item){
// Do something
alert("itemId : " + item.id);
};
GDT.on( MODGLOBALSCOPEVARIABLE.eventKeys.testEvent1,testFunc);
After that you need to trigger the event for example when clicking a button somewhere you use:
GDT.fire(MODGLOBALSCOPEVARIABLE.eventKeys.globalEvents.testEvent1, {objectId:test, othervars:'blabla' } );
note the object you pass is optional.(if the handler method doesn’t require the object.
Does that clear it up?
greetz
Ahhhh ok. Asked mostly out of curiosity, but It’s something I may use. As always, thanks dude!
Somehow I think your mod will be great. By looking at everything in this topic, and your Unfinished AI Internet project, I have come up with my own thoughts of what you are doing. I think this mod will be very fun. Carry on!
Really means a lot, dude! Community support is much appreciated in a time when the forum is quiet.
Hoping to show some screenshots when I have a sufficient build ready.