Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过 get_attribute_by_key 获取 复合属性 爆错 #596

Open
liang-1-qi opened this issue Jan 21, 2025 · 2 comments
Open

通过 get_attribute_by_key 获取 复合属性 爆错 #596

liang-1-qi opened this issue Jan 21, 2025 · 2 comments

Comments

@liang-1-qi
Copy link

error]'float' object is not subscriptable
error during Python call: TypeError: 'float' object is not subscriptable
stack traceback:
[C]: in field 'api_get_attr_of_item_key'
.../maps/EntryMap/script/y3\object\editable_object\item.lua:606: in function 'y3.object.editable_object.item.get_attribute_by_key'

@zhangjun5469
Copy link
Collaborator

zhangjun5469 commented Jan 23, 2025

y3.game:event('键盘-按下', 'SPACE', function ()
    print('你按下了空格键!')
    local sp = y3.item.get_attribute_by_key(201390087, 'ori_speed')
    local pene_phy_ratio = y3.item.get_attribute_by_key(201390087, 'pene_phy_ratio')
    local pene_phy = y3.item.get_attribute_by_key(201390087, 'pene_phy')
    
    print('获取到的属性(ori_speed): ', sp)
    print('获取到的属性(pene_phy_ratio): ', pene_phy_ratio)
    print('获取到的属性(pene_phy): ', pene_phy)
end)

======
尝试了如上的代码,都是可以正常获取到对应属性的,这个接口 get_attribute_by_key 是用来获取物品的基础属性的,请确保入参 key 的准确性,具体查阅:y3\game\const.lua

====
版本信息如下
LuaLib:
y3.version = 250116

Y3编辑器:
2.2.2.711894

@sumneko
Copy link
Member

sumneko commented Jan 23, 2025

发一下代码看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants