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 


Table usage
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Fri Mar 08, 2013 12:49 pm    Post subject: Table usage Reply with quote

Dark Byte wrote:
Something like this (untested)

Code:

t={}
t["hero1"]={}
t["hero2"]={}
t["hero3"]={}

t["hero1"][1]=exphero1lvl1
t["hero2"][2]=exphero1lvl2
...
Expforlvl23forhero1=t["hero1"][23]

Well that hasn't worked so far, still tinkering with it. Newest project does involve a table, I think.
Most of the characters have either 8, or 16 items in inventory. I have the values for each and they go like this:
000 Cypress Stick
001 Club
002 Copper Sword
...
124 Fire of Serenity
125 Gas Canister
126 Padequia Seed

What I ultimately want to do is to select a character(radiogroup), display the items inventory (a listbox(?) derived from the table for each item), then select the item and have that number written into the correct table byte location.

Does the table construction follow the same logic as the listview? ie item>subitem with the number an index value?
EDIT:I found this in LUA
Code:

function addTableItems(itemnum, itemdes)
local tableitems = {itemnum, itemdes}
end

addTableItems{000, 'Cypress Stick'}
addTableItems{001, 'Club'}
addTableItems{002, 'Copper Sword'}
addTableItems{003, 'Iron Claw'}
...
addTableItems{037, "Wayfarer's Clothes"}
...
addTableItems{125, 'Gas Canister'}
addTableItems{126, 'Padequia Seed'}
addTableItems{127, 'Empty'}

The apostrphes gave me fits. I did include one line from the middle, do the quotation marks create problems?
If this is the correct way to add the items to a table, how can I populate a combobox with drop downs?
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Wed Mar 13, 2013 7:43 am    Post subject: Reply with quote

I don't think that addTableItems function does anything. It creates a temporary table called tableitems with only 2 elements: 1,itemnum and 2,itemdes, and then destroys it.

try something like this:
Code:

tableitems={} --create a global table
function addTableItems(itemnum, itemdes)
  tableitems[itemnum]=itemdex --make it so the tableitems table gets an element named "itemnum" and give it the value "itemdex"
end


remember that a table is more a map than an array.
you can do tableitems["sheep"]="BAAAA"


If the elements are numeric without gaps then do something like this:
Code:

sl=combobox_getItems(comboboxobject)
strings_clear(sl)
for i=0,127 do
  strings_add(sl, tableitems[i])
end


and to get the selected index you can then do index=combobox_getItemIndex(comboboxobject)

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Wed Mar 13, 2013 9:22 pm    Post subject: Reply with quote

No gaps so I'll try the loop to add the values.
Once the values are in the table, do you use similar code to "get the value selcted" to change a byte value.

Could this be used in a drop combobox?

AND can comboboxes be nested, ie
the first drop down would display an item place(1-Cool, then the second would displays the items(0-127)?

Will the quotation marks present any provblems?

Thanks
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Thu Mar 14, 2013 4:00 am    Post subject: Reply with quote

Not sure, but you just need to get the itemindex of a combobox and look that up in a table. The table can contain any data

You can enable and update the second combobox after selecting an item from the first combobox

And quotes do not matter

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Mar 16, 2013 10:32 am    Post subject: Reply with quote

The code was added as you suggested
Code:

tableitems={} --create a global table
function addTableItems(itemnum, itemdes)
  tableitems[itemnum]=itemdex --make it so the tableitems table gets an element named "itemnum" and give it the value "itemdex"
end

sl = combobox_getItems(CheatPanel_CEComboBox1)
strings_clear(sl)
for i = 0,127 do
  strings_add(sl, tableitems[i])
end


addTableItems{000, 'Cypress Stick'}
addTableItems{001, 'Club'}
addTableItems{002, 'Copper Sword'}
...

No errors so the code compiles, but the combo box is empty. I've tried printing the table index(es) and I got an error: table index is nil
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Mar 16, 2013 10:47 am    Post subject: Reply with quote

That is because the table is still empty at the time you fill the combobox
_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Mar 16, 2013 2:21 pm    Post subject: Reply with quote

Code:

tableitems={} --create a global table
function addTableItems(itemnum, itemdes)
  tableitems[itemnum]=itemdex --make it so the tableitems table gets an element named "itemnum" and give it the value "itemdex"
end

addTableItems{000, 'Cypress Stick'}
addTableItems{001, 'Club'}
addTableItems{002, 'Copper Sword'}
addTableItems{003, 'Iron Claw'}
...
addTableItems{125, 'Gas Canister'}
addTableItems{126, 'Padequia Seed'}
addTableItems{127, 'Empty'}

sl = combobox_getItems(CheatPanel_CEComboBox1)
strings_clear(sl)
for i = 0,127 do
  strings_add(sl, tableitems[i])
end

Changed the sequence of the code as above, so ummm, how does the table get filled, if the function addTableItems(itemnum, itemdes) doesn't add the items? I still get the table index is nil and nothing in the combobox
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Mar 16, 2013 3:08 pm    Post subject: Reply with quote

I just noticed that you have been using { } to give parameters while you should give ( )


In all the addTableItems calls replace { with ( and } with )

_________________
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
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sat Mar 16, 2013 3:30 pm    Post subject: Reply with quote

Quote:
function addTableItems(itemnum, itemdes)
tableitems[itemnum]=itemdex --make it so the tableitems table gets an element named "itemnum" and give it the value "itemdex"
end


Your param itemdes is not used since you put 'itemdex' (with an x) instead.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Mar 16, 2013 3:45 pm    Post subject: Reply with quote

Yes as I thought tables needed those braces, my stupidity.
Anyway using the above code with brackets in place, now combobox has about 128 #1's nothing else and no item associated with the 1's.
I have the following in TStrings: Num, Itm if that makes a difference
I tried this:
for x = 0, 127 do
print(tableitems[x], x)
end
And got 128 1's no itemdes associated with 1

In the table definition should there be a "subitem" to describe the itemdes?
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Mar 16, 2013 4:51 pm    Post subject: Reply with quote

Did you take into account wiccaans comment? Change itemdex to itemdes

I have an example .ct here (execute the lua script)



example.ct
 Description:

Download
 Filename:  example.ct
 Filesize:  1.1 KB
 Downloaded:  820 Time(s)


_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Mar 16, 2013 5:39 pm    Post subject: Reply with quote

That worked perfectly. The itemnum doesn't show and that is ok, but I need to select that number to insert into an inventory byte.

itemnumber = combobox_getItemIndex(CheatPanel_CEComboBox1)
print(itemnumber)

I keep getting -1 when the drop down arrow is selected.

AutoDropDown
AutoSelect both set to false

EDIT:
If an item is highlighted then the drop down arrow is selected the proper indexnum is printed. I changed the AutoSelect to true, but that didn't help the -1
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Mar 16, 2013 6:02 pm    Post subject: Reply with quote

make sure the style property of the dropdownlist is set to "csDropDownList" so it can't be edited by the keyboard but only selected
_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sat Mar 16, 2013 6:19 pm    Post subject: Reply with quote

It is already. This what the output looks like and the properties.
Notice the -1's. After an item is selected nothing prints, but selecting the same item one or more times prints the index number.



ComboBox.png
 Description:
 Filesize:  59.21 KB
 Viewed:  12515 Time(s)

ComboBox.png


Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Mar 16, 2013 6:29 pm    Post subject: Reply with quote

I have no idea how your events are setup, but use the onChange event (not onclick as that happens before selection)

and make sure that when you populate the list onchange isn't handled

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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