Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Returning value from form when pressed button

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Thu Apr 21, 2022 8:38 am    Post subject: Returning value from form when pressed button Reply with quote

So i'm making a function that will return index of current combo box item but can't realize it in code
function:
Code:

function messageComboBox( name, items)
    local form = createForm(false)
    form.Width = 220
    form.Height = 140
    form.BorderStyle = bsSingle
    form.Position = poScreenCenter
    form.PopupMode = 0
    form.Caption = name

    local combobox = createComboBox(form)
    combobox.Width = 200
    combobox.AnchorSideLeft.Control = form
    combobox.AnchorSideTop.Control = form
    combobox.BorderSpacing.Left = 10
    combobox.BorderSpacing.Top = 5

    local button = createButton(form)
    button.Width = 50
    button.AnchorSideLeft.Control = form
    button.AnchorSideTop.Control = form
    button.BorderSpacing.Left = form.Width / 2
    button.BorderSpacing.Top = 120
    button.Caption = 'OK'

    for i = 0,#items do
      combobox.items.add(tostring(items[i]))
    end

    form.OnClose = function(sender)
      return caFree
    end

    form.Show()

  end

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25287
Location: The netherlands

PostPosted: Thu Apr 21, 2022 8:46 am    Post subject: This post has 1 review(s) Reply with quote

Code:

form.showModal()
return combobox.ItemIndex

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Thu Apr 21, 2022 8:52 am    Post subject: Reply with quote

ty

btw full function:
Code:
function messageComboBox( name, items)
  if type(items) ~= 'table' or items == nil then
    return
  end

  local form = createForm(false)
  form.Width = 400
  form.Height = 55
  form.BorderStyle = bsSingle
  form.Position = poScreenCenter
  form.PopupMode = 0
  form.Caption = name or 'Select Item'

  local combobox = createComboBox(form)
  combobox.Width = form.Width - 20
  combobox.AnchorSideLeft.Control = form
  combobox.AnchorSideTop.Control = form
  combobox.BorderSpacing.Left = 10
  combobox.BorderSpacing.Top = 5

  local button = createButton(form)
  button.Width = 50
  button.AnchorSideLeft.Control = form
  button.AnchorSideTop.Control = form
  button.BorderSpacing.Left = form.Width / 2.5 - 15
  button.BorderSpacing.Top = 30
  button.Caption = 'OK'

  local button1 = createButton(form)
  button1.Width = 50
  button1.AnchorSideLeft.Control = form
  button1.AnchorSideTop.Control = form
  button1.BorderSpacing.Left = button.BorderSpacing.Left + 50
  button1.BorderSpacing.Top = 30
  button1.Caption = 'Cancel'

  for i = items[0] == nil and 1 or 0,#items do
    combobox.items.add(tostring(items[i]))
  end

  form.OnClose = function(sender)
    if combobox.ItemIndex == -1 and not button1.Pressed then
      messageDialog("Item can't be empty!\nPlease select item from box!",mtWarning,mbOK)
      return
    end
    if button.Pressed or button1.Pressed then
      return caFree
    end
  end

  button.OnClick = function(sender)
    button.Pressed = true
    form.Close()
  end

  button1.OnClick = function(sender)
    button1.Pressed = true
    form.Close()
  end

  form.showModal()

  return combobox.ItemIndex >= 0 and combobox.ItemIndex or nil
end

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites