Help. count

Ask gaming related questions (AHK v1.1 and older)
firedmourner
Posts: 2
Joined: 30 Sep 2022, 19:56

Help. count

Post by firedmourner » 30 Sep 2022, 20:04

Code: Select all

setz(zet, zetz) {
	z:=zet
	z2:=zet2
	addChatMessage("{ff87cc}• se: " zet)
	addChatMessage("{ff87cc}• tot: " zet2)
	sendchat("/z " zet)
}
return

next() {
	z += 1
	z2 += 1
	addChatMessage("{ff87cc}• now: " z)
	addChatMessage("{ff87cc}• total: " z2)
	sendchat("/z " z)
return
}
Good day. Example: /setz 1001 0
When I press /next I want to get +1 to each value. But it turns out that z = 1002 and it works fine (adds every time), but z2 is always =1 (it stays the same). What's wrong?
Screenshot_2.png
Screenshot_2.png (70.32 KiB) Viewed 490 times

User avatar
boiler
Posts: 16919
Joined: 21 Dec 2014, 02:44

Re: Help. count

Post by boiler » 30 Sep 2022, 22:56

How are we supposed to help when so much is missing? You posted two functions that aren’t called by anything and don’t call each other. I’m guessing you declared some variables as global, but you haven’t shown that. There’s not enough here to advise on what’s wrong.

firedmourner
Posts: 2
Joined: 30 Sep 2022, 19:56

Re: Help. count

Post by firedmourner » 01 Oct 2022, 06:22

Code: Select all

#include samp-udf.ahk
#include CP.ahk

#IfWinActive, ahk_exe gta_sa.exe
#SingleInstance Force 
#NoEnv

if (A_IsAdmin = false) 
{
    Run *RunAs "%A_ScriptFullPath%" ,, UseErrorLevel
}

ListLines Off
SetBatchLines -1
#SingleInstance, force
#NoEnv
StringCaseSense, Off

global noyname = ""
global chatlog 				:= A_MyDocuments "/RADMIR CRMP User Files/SAMP/chatlog.txt" 
global screens 				:= A_MyDocuments "/RADMIR CRMP User Files\SAMP\screens" 
global config 				:= A_ScriptDir "\other\config.ini"
global z := 0
global totalans := 0
global totaljail := 0
global totalkick := 0
global totalmute := 0
global totalz := 0
global totalmmut := 0
global totalrmute := 0
global totalban := 0
global totalwarn := 0

IfWinNotExist,  GTA:SA:MP
{
    msgbox, u vas yest' 1 minuta, chtoby otkryt' igru
    process, Wait, gta_sa.exe, 60
    Loop
    {
        if (ErrorLevel == 0) {
            msgbox, igra ne otkryta`n`nskript offayetsya
            exitapp
        }
		else {
			SetTimer, start, 50
			Break
		}
    }
}
else {
	SetTimer, start, 50
}

IfNotExist, other
{
    FileCreateDir, other
    IfNotExist, other\done
    {
        FileCreateDir, other\done

        IfNotExist, %config%
        {
            fileappend, , %config%
            IniWrite, 1, %config%, config, all
            IniWrite, 300, %config%, config, normareport
            IniWrite, 20, %config%, config, normajail
            IniWrite, 50, %config%, config, normakick
            IniWrite, 5, %config%, config, normamute
            IniWrite, 50, %config%, config, normaz
            IniWrite, 0, %config%, config, autospec
            IniWrite, 0, %config%, config, autor
            IniWrite, 0, %config%, config, copys
        }
    }
}

CMD.Register("atinfo","atinfo")
CMD.Register("clearst","clearst")
CMD.Register("gec","gec") 
CMD.Register("ass","ass")
CMD.Register("rws","rws")
CMD.Register("unf","unf")
CMD.Register("oskrod","oskrod")
CMD.Register("adm","adm")
CMD.Register("prev","prev")
CMD.Register("now","now")
CMD.Register("mpgun","mpgun")
CMD.Register("setz","setz")
CMD.Register("next","next")
CMD.Register("clea","clea")
exit

setz(zet, zetz) {
	z:=zet
	z2:=zet2
	addChatMessage("{ff87cc}• se: " zet)
	addChatMessage("{ff87cc}• tot: " zet2)
	sendchat("/z " zet)
}
return

next() {
	z += 1
	z2 += 1
	addChatMessage("{ff87cc}• now: " z)
	addChatMessage("{ff87cc}• total: " z2)
	sendchat("/z " z)
return
}
There is nothing more to this, nothing else applies.
I need to set 2 values ​​(example: 100, 0). When I switch with the /next command, it should open 101, 102 and etc, and the second value should count the number of openings with the /next command

I can set the value to 600000 instead of 100, but the second value should count the number of openings. Help, tell me the easiest way to do this.
sendchat("/z " zet) This command opens 101,102,103 - works now. It just doesn't count the second value, the value is always = 1.

User avatar
boiler
Posts: 16919
Joined: 21 Dec 2014, 02:44

Re: Help. count

Post by boiler » 01 Oct 2022, 07:01

Maybe others can help without seeing how those functions are called, which still isn't shown since you didn't show the included files. I won't be digging into all of that anyway, but I think whoever helps you will need that unless they are already familiar with it.

Moving this thread to the "Gaming" section of "Ask For Help".

Descolada
Posts: 1126
Joined: 23 Dec 2021, 02:30

Re: Help. count

Post by Descolada » 01 Oct 2022, 08:47

It doesn't work because z is defined as a super-global variable with global z := 0, whereas z2 isn't and thus by default is a local variable which is forgotten on every new call of next().
Fix: either add global z2 := 0 as well, or define z2 as a static variable inside next() (if it isn't needed in other functions):

Code: Select all

next() {
	static z2
	z += 1
	z2 += 1
	addChatMessage("{ff87cc}• now: " z)
	addChatMessage("{ff87cc}• total: " z2)
	sendchat("/z " z)
return
}

Post Reply

Return to “Gaming Help (v1)”