Log in to reply
 

[HELP C#] function don't work



  • I do not know how to use C # very well but I do not understand why this code does not work, I need to set up more buttons via ini, and they press 1 to do the mod (this works) and pushing others perform the functions. but it does not work, this is the code, can you help me? thank you so much

    Keys toggleScreen;
    public Class1()
    {
    	this.Tick += onTick;
    	this.KeyUp += onKeyUp;
    	this.KeyDown += onKeyDown;
    	if (toggle)
    	{
    		this.KeyUp += ScreenFunction;
    	}
    	ScriptSettings config = ScriptSettings.Load("scripts\\mod.ini");    //Read Ini
    	toggleMod = config.GetValue<Keys>("ScreenKeys", "StartMod", Keys.F12);
    	toggleScreen = config.GetValue<Keys>("ScreenKeys", "DoScreenShot", Keys.NumPad0);
    }
    
    private void onKeyUp(object sender, KeyEventArgs e)
    {
    	if (e.KeyCode == toggleMod)
    	{
    		toggle = true;
    	}
    }
    void ScreenFunction(object sender, KeyEventArgs screenKey)
    {
    	if (screenKey.KeyCode == toggleScreen)
    	{
    		UI.ShowSubtitle("hello");
    	}
    }
    

  • MODERATOR

    @Santo99 What are you wanting it to do?



  • @Jitnaught said in [HELP C#] function don't work:

    What are you wanting it to do?

    i edit the post some part was missing, anyway, i need to Press F12 to start the mod, after if i press NumPad0, show my a notify


  • MODERATOR

    @Santo99
    I'm guessing the problem is that pressing toggleScreen button doesn't work. I'm going to guess it's because by default the toggle variable is set to false (you don't show the declaration of the variable so I don't know for sure). This means that the ScreenFunction function isn't added to the KeyUp event handler, which means your code will never be called.

    What you should do is copy the code in your ScreenFunction function to the onKeyUp function, then remove ScreenFunction entirely. Then change "screenKey.KeyCode" to "e.KeyCode", and add another check for if toggle == true.



  • @Jitnaught thanks a lot!! many hours for this stupid error :|


  • MODERATOR

    @Santo99 If you have any more questions later feel free to PM me here or on Discord (username: Jitnaught#4171). :)


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.