в консоль сампфункс выводятся непонятные адреса памяти, а мне нужно что бы выводились…
- User
в консоль сампфункс выводятся непонятные адреса памяти, а мне нужно что бы выводились значения переменных
11 local str1 12 local str2 13 local str3 14 local Nick 15 local Az 16 local Dep 31 local stats = {} 54 function sampev.onShowDialog(id, style, title, button1, button2, text) 55 for line in text:gmatch('[^\r\n]+') do 56 if line:find('Деньги на депозите') then 57 str1, Dep = line:match('(.*)%[(%$%d+)%]') 58 end 59 if line:find('Имя: ') then 60 str2, Nick = line:match('(.*)%[(%w+_%w+)%]') 61 end 62 if line:find('Текущее состояние счета: ') then 63 str3, Az = line:match('(.*)(%d+.*)') 64 end 65 table.insert(stats, {Az, Nick, Dep}) 66 for i = 1, #stats do 67 print(stats[i]) 68 end 69 end 70 end - Assistant
The issue you're encountering is due to how Lua handles printing tables. When you directly print a table using
print(stats[i]), Lua outputs the memory address of the table (e.g.,table: 0x7ffdeadbeef), not its contents. This is why you're seeing "unintelligible memory addresses" in the console.To print the values stored in the table, you need to access the individual elements within the table and print them. In your code, each
stats[i]is a table containing{Az, Nick, Dep}. Here's how you can modify your code to print the actual values:Option 1: Access Each Element Individually
66 for i = 1, #stats do 67 print(stats[i][1], stats[i][2], stats[i][3]) 68 endOption 2: Use
table.unpackto Unpack the Table66 for i = 1, #stats do 67 print(table.unpack(stats[i])) 68 endOption 3: Format the Output for Clarity
66 for i = 1, #stats do 67 print(string.format("Az: %s, Nick: %s, Dep: %s", tostring(stats[i][1]), tostring(stats[i][2]), tostring(stats[i][3]))) 68 endBy accessing the elements directly, you're telling Lua to print the contents of the table rather than its memory address.
Updated Code Example:
function sampev.onShowDialog(id, style, title, button1, button2, text) for line in text:gmatch('[^\r\n]+') do if line:find('Деньги на депозите') then str1, Dep = line:match('(.*)%[(%$%d+)%]') end if line:find('Имя: ') then str2, Nick = line:match('(.*)%[(%w+_%w+)%]') end if line:find('Текущее состояние счета: ') then str3, Az = line:match('(.*)(%d+.*)') end end table.insert(stats, {Az, Nick, Dep}) for i = 1, #stats do print(stats[i][1], stats[i][2], stats[i][3]) end endExplanation:
- Accessing Table Elements:
stats[i][1],stats[i][2], andstats[i][3]refer toAz,Nick, andDep, respectively. - Printing Values: By passing these elements to
print, you output their values instead of the table's memory address.
Additional Tips:
- Ensure Variables are Populated: Make sure that
Az,Nick, andDepare properly assigned before inserting them intostats. - Use Clear Variable Names: For better code readability, consider using named keys in your tables (e.g.,
stats[i].Az), though this would require modifying how you insert data intostats.
Modified Insertion with Named Keys:
table.insert(stats, {Az = Az, Nick = Nick, Dep = Dep})And then print:
print(stats[i].Az, stats[i].Nick, stats[i].Dep)By making these changes, your console output should now display the values of
Az,Nick, andDepas intended.Summary: Replace
print(stats[i])withprint(stats[i][1], stats[i][2], stats[i][3])to display the variable values instead of memory addresses.Answer:
Because stats[i] is a table, printing it shows its address—so to print the values, change line 67 to print(stats[i][1], stats[i][2], stats[i][3])
- Accessing Table Elements: