Nilom's Recent Forum Activity

  • Not really sure exactly how you plan to save and load all the data

    I will save to and load them from Mongodb using the Realm Web SDK.

    Depending on your needs you might be able to get away with something easier though.

    If your data objects don't have nested properties (properties which are objects or arrays with more data in them), you can rather easily use Object.assing to create a new object with the properties from a list objects.

    I think I will need nested objects. One of the templates could look like this:

    {
    	templates: {
    		"weapons": {
    			"background_color": "100,0,0",
    			"name": {
    				"x": 25,
    				"y": 5,
    				"font_size": 16,
    				"font_style": "bold"
    			},
    			"picture": {
    				"x": 5,
    				"y": 20,
    				"width": 50,
    				"height": 50
    			},
    			"text": {
    				"x": 10,
    				"y": 100,
    				"font_size": 10,
    			}
    		}
    	}
    }

    I do not know beforehand how many of these properties a template will have because the player can insert more than one text or more pictures in the items.

    Using this approach you can allow the player to select a base item, then a specific one, merge them and the result becomes the new item.

    This sounds like what I'm trying to do. Too bad .assign doesn't work with nested objects. It looks clean and simple without 2 huge code blocks just to link an object to another one.

    Thank you again for the example! I looked into classes. They seem to be almost the same thing as Prototypes. Maybe better readable.

    Now I wonder if I'm overcomplicating things and if I really need this. Or if I should just store the templates as a JSON in a document inside Mongodb and just create all the text objects, sprites etc. from the selected template and then just let the player be able to edit from there.

  • DiegoM Many thanks for the detailed reply! Your way of organizing the common properties and classes looks way better.

    I'm not sure if deep merge is what I wanted to do. Basically I do not know how I can set an object to have a prototype to lookup for default values.

    This is what I meant. There are many different ways listed and I'm not sure which one to choose.

    An important detail that I forgot to mention is that I need to be able to manipulate the objects prototypes at runtime.

    Explanation:

    The player will be able to create new items and he can create them from templates that he created beforehand.

    For example let's say he creates a new item called Allmighty Wizard Staff. Because he already created a template staff before he now defines that the Allmighty Wizard Staff uses this template. So when he creates 30 more staffs he doesn't need to define all the default values again.

    Now I want the app to be able to set the Allmighty Wizard Staffs prototype to staff.

    WackyToaster Could this be achieved with classes?

    Or does this mean that I should use Object.setPrototypeOf()?

    Thanks for helping me!

  • Hello there!

    I wonder how objects can inherit/copy other objects keys/values.

    I watched some videos and read through some explanation pages about prototypes, constructors and stuff, but found it a bit confusing.

    Some of them say don't do that. Don't use this. Since ES6 this is obsolete. This is old. Even though you can still do this, you should do that instead etc. etc. .

    Maybe someone can explain this to me how it can be done before I spend another 5 hours finding the up-to-datest or best way to inherit one objects properties into another ones.

    What I'm trying to do is as follows: I want to have objects that are "templates" for other objects.

    Let's have an example. An RPG.

    There could be a template with the key weapons, one with the key armors, spells and one with the key items.

    This are just fantasy values but the JSON could look like this:

    {
    	"templates": {
    		"rarities": {
    			"colors": {
    				"common": "80,80,80",
    				"rare": "0,0,80",
    				"epic": "90,0,80"
    			}
    		},
    		"weapons": {
    			"color": "100,0,0",
    			"name": {
    				"x": 25,
    				"y": 5,
    				"font_size": 16,
    				"font_style": "bold"
    			},
    			"text": {
    				"x": 10,
    				"y": 50,
    				"font_size": 12,
    				"font_style": ""
    			},
    			"picture": {
    				"x": 0,
    				"y": 20,
    				"width": 50,
    				"height": 50
    			},
    			"attack": {
    				"x": 40,
    				"y": 5,
    				"font_size": 18,
    				"font_style": "bold",
    				"icon": "sword"
    			}
    		},
    		"spells": {
    			"color": "0,0,100",
    			"name": {
    				"x": 25,
    				"y": 5,
    				"font_size": 16,
    				"font_style": "bold"
    			},
    			"text": {
    				"x": 10,
    				"y": 120,
    				"font_size": 12,
    				"font_style": "italic"
    			},
    			"picture": {
    				"x": 0,
    				"y": 20,
    				"width": 50,
    				"height": 100
    			},
    			"cost": {
    				"x": 40,
    				"y": 5,
    				"font_size": 18,
    				"font_style": "bold",
    				"icon": "mana"
    			}
    		}
    	}
    }

    Now if I create new weapons in the JSON I do not want to always define where the x and y positions of the weapons name should be or where it's picture should be etc. .

    {
    	"items": {
    		"weapons": {
    			"1": {
    				"name": "Axe",
    				"text": "Great for cutting trees.",
    				"attack": 5,
    				"rarity": "common"
    			},
    			"2": {
    				"name": "Rusty Sword",
    				"text": "Not a great sword at all.",
    				"attack": 7,
    				"rarity": "common"
    			},
    			"3": {
    				"name": "Rusty Greatsword",
    				"text": "A greatsword which is not a great sword either.",
    				"attack": 10,
    				"rarity": "common"
    			}
    		}
    	}
    }
    

    1) How can I inherit the templates properties? Is there a way how I can have all of the entries under the key "weapons" have the properties of the weapons template or do I have to "link" the weapon template to each of the weapons individually?

    Oh and bonus question:

    2) Should I instead of an ID as the key name use the weapons name as the key name? Or an array?

    {
    	"weapons":{
    		"Axe": {
    			"text": "Great for cutting trees.",
    			"attack": 5,
    			"rarity": "common"
    		},
    		"Rusty Sword": {
    			"text": "Not a great sword at all.",
    			"attack": 7,
    			"rarity": "common"
    		},
    		"Rusty Greatsword": {
    			"text": "A greatsword which is not a great sword either.",
    			"attack": 10,
    			"rarity": "common"	
    		}
    	}
    }
    

    Thanks for reading and thank you for explaining it to me. :D

  • Good idea.

  • lennaert

    Thank you for this different point of view. I think this makes the most sense to me now.

    I like to safe time on edits and modifications. I do a lot of edits because I am kind of a of perfectionist.

    I will do that as follows:

    Host group:

    • Authoritarian events

    Peer group:

    • "Streamed" events

    (Semi) common group:

    • Events that share the same logic but behave differently for host and peers
  • Okay what you say makes sense.

    I will strictly separate the events because if I have a bug one day that might allow people to cheat or mess up everything.

  • Hey there!

    I wonder which of these schemas I should use:

    1)

    • Have a group for all events that are host only
    • Have a group for all events that are peer only
    • And have a group for all common events which are exactly the same

    2)

    • Have a group for all events that are host only
    • Have a group for all events that are peer only
    • And have a group for all common events which are mostly the same and just use is host or is peer for the adaptions

    Example for 2):

    On peer message
    		ChatAppend("[" & Multiplayer.FromAlias & "]: " & Multiplayer.Message)
    	Is host
    		Broadcast message to other peers
    

    Should I strictly separate host events and peer events or should I save on the amount of events needed?

    How do/would you do it?

    Thank you in advance!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can define global variables in the main.js script inside runOnStartup to have it run before the layout.

  • Okay I will discard this idea and just use different JSON objects.

  • Hey there!

    I want to store all of my relevant data like localization, ui position, button sizes for the mobile or pc version in a single JSON object.

    Is there a way how I can parse/load multiple .json project files into a single JSON object?

    For example load english_localization.json & interface_data.json & variables.json into Data (name of JSON object).

    So that I can do things like:

    Data.localization.main_menu.header
    Data.ui.pc.main_menu.header.x
    Data.ui.pc.main_menu.header.y
    Data.ui.pc.main_menu.header.font_size
    

    ...

    OR

    ...

    Data.ui.mobile.main_menu.header.x
    Data.ui.mobile.main_menu.header.y
    Data.ui.mobile.main_menu.header.font_size
    

    More specifically:

    Data.Get(".ui.mobile.main_menu.header.font_size")
    

    So for example a menus header text position could be set to:

    x:

    Data.Get(".ui." & platform & ".main_menu.header.x")
    

    y:

    Data.Get(".ui." & platform & ".main_menu.header.x")
    

    Where platform is either pc or mobile.

    Oh and my other question is: Is that a good practice?

    I imagine it being handy to have every data at one place instead of mixing json and global variables. I want to have a modular interface where I can use the same events with different pc/mobile values instead of having double the event count.

  • When a player collects a coin you add +1 to the variable coins. If coins are x (the number needed) you let the goal appear.

  • I got it to work.

    But I had to use runtime.objects.Language.getFirstInstance().

    Now I have two working solutions for the problem that I had.

    This is how the script looks now.

Nilom's avatar

Nilom

Member since 26 Dec, 2019

Twitter
Nilom has 1 followers

Trophy Case

  • 4-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • x2
    Great Comment One of your comments gets 3 upvotes
  • Email Verified

Progress

9/44
How to earn trophies