[help] to key toggle


#1

how can i make this toggle on key pres . i have tried to get it work but i can’t

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustPressed( 0, 10 ) then
SetRadarBigmapEnabled(true)
end
end
end)


#2

Next time please put your code a code block with some indentation (``` at the start and end)

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
    if IsControlJustPressed(0, 10) then
      SetRadarBigmapEnabled(true)
    end
  end
end)

What your code does is, do nothing until control #10 (Page Up) is pressed. Once it has been pressed call SetRadarBigmapEnabled(true) then, do nothing until page up is pressed, when it has been call SetRadarBigmapEnabled(true) again and so on.
This means every time the key is pressed it will make the radar expand, not close and open it like I presume you want it too

This code should work

Citizen.CreateThread(function()
  local toggle = false -- Create the variable which will change
  SetRadarBigmapEnabled(toggle) -- Call the function with the variable we just created (to set it to the default we want it to be; in this case false)
  while true do
    Citizen.Wait(0)
    if IsControlJustReleased(0, 10) then -- Checking if it was released rather than pressed is better
      toggle = not toggle -- Invert current value of the variable (not true = false, not false = true)
      SetRadarBigmapEnabled(toggle) -- Call the function again with the same variable (which should now be inverted)
    end
  end
end)

#3

Thank you soo much .

I did not know that I could put code in a box . but now i know :smiley: