Please add more templates and tutorials on scripting

2 favourites
From the Asset Store
Fruit Slicer Template & Quality fruit and slice graphics (c3p,png,illustrator files)
  • Ashley, Nepeo - first of all, thank you for this great feature!

    As I understand, the main idea of scripting is to extend events, not replace them. Unfortunately, there is currently only one template (Ghost Shooter), and it doesn't provide much information on using scripting in combination with event sheets.

    So could you please add more templates/tutorials for people like me not very experienced with JavaScript, demonstrating how to use scripts integrated with events. Particularly:

    • When object instances are picked by event, how to pick same instances in the script. For example, I have an event "Player has LOS to Enemy", inside it a JS function "MarkEnemies()" is called, will it automatically pick the same enemy instances as the parent event?
    • Different ways to pass information from the script back to events - set global/local variables, call C3 functions etc.
    • How to use object's triggers, conditions and run actions from the script? For example, if I need to change Bullet angle, I should call something like Player.Bullet.SetAngleOfMotion(n) - what is the correct syntax and where can I find this action/method name?
  • I currently have 2 games that demonstrate how to mix events and java script, they are not really tutorials but going through might help a bit. you can get the c3p files here

    https://www.patreon.com/posts/tank-trax-clone-28597133

    https://www.patreon.com/posts/word-finder-28761484

    with that said It would be nice to see some more official templates integrating the scripting feature

  • Awesome, thank you!

  • When object instances are picked by event, how to pick same instances in the script. For example, I have an event "Player has LOS to Enemy", inside it a JS function "MarkEnemies()" is called, will it automatically pick the same enemy instances as the parent event?

    Scripting has no concept of picking. That whole concept is unique to Construct's event system. However you can access the picked instances from script using the IObjectClass methods, e.g. the pickedInstances() iterator.

    Different ways to pass information from the script back to events - set global/local variables, call C3 functions etc.

    That's already covered by the Integrating events with script example.

    How to use object's triggers, conditions and run actions from the script? For example, if I need to change Bullet angle, I should call something like Player.Bullet.SetAngleOfMotion(n) - what is the correct syntax and where can I find this action/method name?

    All available calls are documented in the scripting reference section of the manual. However behavior calls aren't yet supported - it's on the todo list.

  • Thanks, Ashley. I've studied the documentation. But as I said, as someone who is not very experienced with Javascript and has little understanding of how Construct 3 works internally, I still struggle trying to write my own scripts.

    It would help beginners a lot if you could maybe add more code snippets to the documentation, or create a few more templates/tutorials.

    All available calls are documented in the scripting reference section of the manual. However behavior calls aren't yet supported - it's on the todo list.

    What about object's conditions and actions? For example, "Sprite Is overlapping another object" or "Dictionary set key" - how do I call these from the script?

  • What about object's conditions and actions? For example, "Sprite Is overlapping another object" or "Dictionary set key" - how do I call these from the script?

    There isn't any way to call arbitrary conditions/actions/expressions, and probably won't be, because as I mentioned these fundamentally rely on picking which isn't a concept in scripting. There are alternatives though, such as the method to test for an overlap between two instances, or script interfaces to access specific features like dictionary keys. These are the kinds of building blocks that the Construct engine itself is built from, and these are the same things you can use in scripting to build your game out of as well.

  • I agree with Doop

    will be nice to have more scripting Temples to study if possible:

    Example:

    I'm stuck how to pick by UID

    or

    How to filter the picking using scripting

    or

    How to check an instance Boolean if is true or Check instance Variable

    or

    How to set a boolean to false

    or

    How to check if an object is Solid because has the solid behaviour

    etc....

    Also, I think important info like this:

    Scripting has no concept of picking. That whole concept is unique to Construct's event system. However you can access the picked instances from script using the IObjectClass methods, e.g. the pickedInstances() iterator.

    It should be more accessible, for example here:

    construct.net/en/forum/construct-3/scripting-51/getting-started-javascript-144301

    That's is the first place I went to start with the scripting.

    And also I think anyone that comes from using C2 and picking, UID, etc... like me, he would like to know what is the alternative for

    "Scripting has no concept of picking"

    And stuff like that, because I spend many hours today looking how to pick by UID but still couldn't find it yet

    Thanks for scripting, by the way, it's really Awesome to have it and is gonna be really helpful to learn to code

  • I currently have 2 games that demonstrate how to mix events and java script, they are not really tutorials but going through might help a bit. you can get the c3p files here

    https://www.patreon.com/posts/tank-trax-clone-28597133

    https://www.patreon.com/posts/word-finder-28761484

    with that said It would be nice to see some more official templates integrating the scripting feature

    I couldn't find any of the tutorials, have they been removed?

  • https://piranha305.itch.io/tanktrax has the c3p file for the tank game.

  • https://piranha305.itch.io/tanktrax has the c3p file for the tank game.

    Ho Woow Thanks very much that is gonna be really helpful :)

    Any chance that you know how to pick by UID?

    They have it here but it doesn't say how to use it

    https://www.construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/object-interfaces/iinstance

  • Yes so there are essential 2 ways to go about it, you either let the conditions on the event sheet pick the object for you, or you iterate over all the objects and look for the uid your looking for

    here is a quick test project https://drive.google.com/open?id=1UExW5rLfhDLtEhr0nPaT7KlX-VjjMryT

    it show both ways of picking, using a condition to guide your picking, and a purely picking in scripting (not sure if using the event system to pick has any optimizations as opposed to iterating over all the obejcts) but with that said you can merge both approaches pretty seamlessly, narrow down you instance list with a condition and then in JS, you can further narrow down and target the instances you want to deal, with, you can even abstract it out into a function that will return the specific set of IWorldInstances you want to deal with.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i went a bit overboard with the iterating the text input, if you know you only have one instance of sometime you can simplify it by using something

    	const textInput = runtime.objects.TextInput.getAllInstances()[0];
    

    you don't really need the first for..of loop

  • Yes so there are essential 2 ways to go about it, you either let the conditions on the event sheet pick the object for you, or you iterate over all the objects and look for the uid your looking for

    here is a quick test project https://drive.google.com/open?id=1UExW5rLfhDLtEhr0nPaT7KlX-VjjMryT

    it show both ways of picking using a condition to guide your picking, and a purely picking in scripting (not sure if using the event system to pick has any optimizations as opposed to iterating over all the obejcts) but with that said you can merge both approaches pretty seamlessly, narrow down you instance list with a condition and then in JS, you can further narrow down and target the instances you want to deal, with, you can even abstract it out into a function that will return the specific set of IWorldInstances you want to deal with.

    Awesome!! Thanks so much for your help and for Commenting the whole process really helpful, I really appreciate it, I'm gonna play with it see how far I can go ))

    (not sure if using the event system to pick has any optimizations as opposed to iterating over all the obejcts)

    I see, good question I was looking for that Answer too lol, I hope Ashley can give us some hints, I was looking for how to Pick by UID because I thought that would be the most optimized method like when we pick with the Events & UID but it looks like with JS is all a bit different, there is a lot to learn jeje, will be nice to see some BenchMarks of at least the Picking which one is faster ) and different benchmarks also anything related to (JS Vs Events) I'm surprised no one has done it yet as it's been quite a while since the Scripting has been released

  • i went a bit overboard with the iterating the text input, if you know you only have one instance of sometime you can simplify it by using something

    > 	const textInput = runtime.objects.TextInput.getAllInstances()[0];
    

    you don't really need the first for..of loop

    Ho cool no worries, Thanks for the update

    Lots of good info today hope I can learn some Js quick

  • so iterating over instances should be pretty fast. the optimization would be in caching, like the uid of instances don't really change so when you find it once, you can store it, and then access it for all other operation you need and those look ups would be a bit faster. since you don't have to iterate over all the instances again, but that's very negligible unless you have 1000+ instances

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)