struct User {
address OwnerAddress;
string Name;
uint256[] OwnedProducts;
}

struct Product {
address ProductOwnerAddress;
string ProductName;
uint256 ProductId;
}

mapping(address => User) users;
mapping(uint256 => Product) products;

function CreateUser(string memory UserName) public {
require(users[msg.sender].OwnerAddress != msg.sender, "Account is already created");
users[msg.sender] = User({
OwnerAddress: msg.sender,
Name: UserName,
OwnedProducts: [0]
});
}

what's wrong here?

TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint8[1] memory to uint256[] memory requested

Jun 12, 2022, 10:12 PM
OwnedProducts: OwnedProducts.push([0]) like that?
How can I push while creating a user?
Jun 12, 2022, 10:19 PM
😢
Jun 12, 2022, 10:22 PM
oh :(
Jun 12, 2022, 10:23 PM
hello president, welcome to solidity.
You cannot push an index into an array
Jun 12, 2022, 10:26 PM
ok, but what can i do?
Jun 12, 2022, 10:28 PM
your syntax is strange, why you do users[msg.sender] = User({
you can do like

User storage user = users[msg.sender];
user.OwnerAddress = msg.sender;
user.Name = UserName;
user.OwnedProducts = [0];
Jun 12, 2022, 10:33 PM
easier to read i think
it works! thanks bro
Jun 12, 2022, 10:37 PM
wtf 😄
Jun 12, 2022, 11:13 PM
https://paste.ofcode.org/rgmtDPwGXEksxjBgnNB66A

everything works but when I return the user struct, the ownedproducts do not return
Jun 13, 2022, 12:43 AM

© 2024 Draquery.com All rights reserved.