SoupOrWorm's Recent Forum Activity

  • Hey, a while ago I made *ahem stole* this script that detects a mouse button press even if it is a side button like FWD/BWD:

    // Import any other script files here, e.g.:
    // import * as myModule from "./mymodule.js";
    
    let r;
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    	r=runtime;
    });
    
    async function OnBeforeProjectStart(runtime)
    {
    	// Code to run just before 'On start of layout' on
    	// the first layout. Loading has finished and initial
    	// instances are created and available to use here.
    	document.addEventListener("mousedown", (e) => {e.preventDefault(); mousedown(e.clientX, e.clientY, e.button)});
    	
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function mousedown(x, y, button){
    	console.log(button);
    	r.globalVars.mouseButtonNum = button;
    }
    
    function Tick(runtime)
    {
    	
    }
    

    Here is the very short events/vars nessesary:

    There are 2 major issues with this system that I need to fix:

    1. It only works if you press a diffrent mouse button before the one you are pressing (e.x. pressing RMB then LMB works, but if you press LMB twice it doesn't work the second consecutive time)

    2. There is no way to check if you are holding the button.

    If anybody knows how I can alter the code/events to fix those issues, please let me know.

  • This is possible with HTLM layers

    https://www.construct.net/en/make-games/manuals/construct-3/tips-and-guides/html-layers

    Worked, thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I want a sprite with 70 opacity to be in front of a slider but it isnt. How do I make it?

    Tagged:

  • Not sure about going with 1.05... The 1 in the formula should stay constant afaik and I don't know about the ramifications. Maybe it's fine?

    This formula will be somewhat different to the framerate dependent lerp and you should adjust the factor accordingly. Basically the higher the factor, the slower the speed.(As opposed to the other way around) I found I'm having to use very small values to make it snappy, like 0.000000001

    But the point is it's framerate independent so even if it's slower than it should be, it will be so across all framerates.

    Got it, thanks.

  • lerp(current, target, 1-factor^dt)

    Thanks for the response. I tried this and it is much faster, but still a bit slower than it should be. Maybe this is because of performance when testing it while it was framerate-dependent? Anyway, changing it to lerp(current, target, 1.05-factor^dt) works, so should I just use 1.05 for all of them? Or do I need to change it for each lerp() individually? Thanks.

  • Hey, I am trying to make everything in my game frame-rate independent, but I noticed that if I just multiply, say, the rate in a lerp function that is called every tick by dt, then it makes it much slower.

    Is there anything that I can always add/multiply to it in addition to multiplying it to dt to make it retain its speed? Right now I am just adding a certain amount to each individual instance with trial and error, but that is inefficient and not precise.

    Tagged:

  • You can do this:

    But I'm not an expert in JS, so this solution may not be a good one.

    It works, thanks!

  • Here is the file if its an issue with the events or project structure or smth. dropbox.com/scl/fi/vo2upm80wnszgkgad2iik/mousebuttontest.c3p

  • Have you tried this?

    runtime.globalVars.varName = button;

    Thanks for the response. I just tried this, but it doesn't seem to be working looking at the devtools. Any idea why?

    // Import any other script files here, e.g.:
    // import * as myModule from "./mymodule.js";
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    });
    
    async function OnBeforeProjectStart(runtime)
    {
    	// Code to run just before 'On start of layout' on
    	// the first layout. Loading has finished and initial
    	// instances are created and available to use here.
    	document.addEventListener("mousedown", (e) => {e.preventDefault(); mousedown(e.clientX, e.clientY, e.button)});
    	
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function mousedown(x, y, button){
    	console.log(button);
    	runtime.globalVars.mouseButtonNum = button;
    }
    
    function Tick(runtime)
    {
    	
    }
    
  • Bear with me, because I am very new to JS.

    Here is my code for getting the mouse button (including forward and backward) in JS:

    // Import any other script files here, e.g.:
    // import * as myModule from "./mymodule.js";
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    });
    
    async function OnBeforeProjectStart(runtime)
    {
    	// Code to run just before 'On start of layout' on
    	// the first layout. Loading has finished and initial
    	// instances are created and available to use here.
    	document.addEventListener("mousedown", (e) => {e.preventDefault(); mousedown(e.clientX, e.clientY, e.button)});
    	
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function mousedown(x, y, button){
    console.log(button);
    }
    
    function Tick(runtime)
    {
    	// Code to run every tick
    }
    

    Simply put, I want to use the 'button' number variable in an event sheet, with as little extra code useage as possible. Any ideas?

  • > I use the current layer numbers to spawn objects in event sheets, so they will be on the wrong layer if I dont manually change all of them

    That's why you should always name your layers properly and use layer names (not numbers) in all events.

    Oh, I didn't know I can just use the names. Well that should make things easier in the future.

  • The only way to do this is to move it to another layer.

    The only reason why I am not just doing that is because I want to put an object on the very bottom layer, but if I make a new layer on the bottom it pushes all of the layer numbers up one. that's an issue because I use the current layer numbers to spawn objects in event sheets, so they will be on the wrong layer if I dont manually change all of them

    Is there any other workaround to this (such as manually changing the layer numbers), or do I have to manually change all of the numbers in the event sheets?

SoupOrWorm's avatar

SoupOrWorm

Member since 7 May, 2021

None one is following SoupOrWorm yet!

Trophy Case

  • 3-Year Club
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

6/44
How to earn trophies