Help with charm and lyra

Lyra is supposed to be the source of truth so how would I go about using charm-sync with lyra since atoms can be modified from anywhere and wont that make lyra not the source of truth
85 Replies
Jolly Pizza
Jolly PizzaOP•4mo ago
idk if this is a stupid question but idk dont bully me for using lyra :pls:
PepeElToro41
PepeElToro41•4mo ago
haha look at him, hes using lyra :spanishkek:
Jolly Pizza
Jolly PizzaOP•4mo ago
:HAHHAHAHA:
PepeElToro41
PepeElToro41•4mo ago
so the problem is that, charm was supposed to be the source of truth too
Jolly Pizza
Jolly PizzaOP•4mo ago
:hmm:
PepeElToro41
PepeElToro41•4mo ago
so you've got a conflict there
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
but then what happens when someone modifies the atom lyra is no longer in sync
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
yeah so i gotta ditch charm or smth :Sadge:
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
huh
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
how do that me noob at charm šŸ™
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
:grubnote:
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
yeah ik
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
but what it atoms get updated somewhere else do i just write a note to myself not to do that
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
so just use like readonly atoms somehow
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
like
function getPlayerData() {
return playerDataAtom()
}
function getPlayerData() {
return playerDataAtom()
}
as like an example return* @PepeElToro41 do you have any other ideas or nah
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
I would not manipulate the player atom at all and just use lyra callbacks entirely to update the charm state
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
I did but like still kinda confused kk
PepeElToro41
PepeElToro41•4mo ago
if you want to modify the money, you'd use lyra transactions or something idk how it works but yeah everything from lyra or a better one, dont use lyra :jukes:
Jolly Pizza
Jolly PizzaOP•4mo ago
:imsad:
PepeElToro41
PepeElToro41•4mo ago
I just use document-service to retrieve/save my data
Jolly Pizza
Jolly PizzaOP•4mo ago
would just a custom impl of smth similar to charm work since im only using it for the sync part :shrug:
PepeElToro41
PepeElToro41•4mo ago
the data is ignored entirely after that probably not I think it would be easier to reconcile the atom
Jolly Pizza
Jolly PizzaOP•4mo ago
how do you do that
PepeElToro41
PepeElToro41•4mo ago
than reconciling the client
Jolly Pizza
Jolly PizzaOP•4mo ago
can you give me an example pls
PepeElToro41
PepeElToro41•4mo ago
No description
PepeElToro41
PepeElToro41•4mo ago
changedCallbacks
Jolly Pizza
Jolly PizzaOP•4mo ago
what does reconcile atom mean sorry im really slow :stare:
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
Im trying to find what are those "changedCallbacks" lyra documentation is confusing
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
aaaaa hated that
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
No description
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
here it is in the api part of the docs
PepeElToro41
PepeElToro41•4mo ago
isnt that the idea
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
aaaaa yeah idk then, delete your project or something
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
no wonder why your code is breaking :dead:
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
yall lowk confusing me frfr ima just go uhh use charm :yeah:
Jolly Pizza
Jolly PizzaOP•4mo ago
yeah this is so easy :sunglas:
No description
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
export interface PlayerData {...}

type PlayerDataMap = {...}

export const PlayerDataAtom = atom<PlayerDataMap>({});

const playerStore = createPlayerStore<PlayerData>({
...,
changedCallbacks: [
(key: string, newData: PlayerData) => {
PlayerDataAtom((prev) => ({
...prev,
[key]: newData,
}));
},
],
});

subscribe(PlayerDataAtom, (newData, oldData) => {
for (const userId in newData) {
const currentData = newData[userId];
const previousData = oldData?.[userId];

const userIdNumber = tonumber(userId);

if (!userIdNumber) {
warn(`Invalid userId: ${userId}`);
continue;
}

if (currentData && currentData !== previousData) {
const player = Players.GetPlayerByUserId(userIdNumber);
if (!player) {
warn(`Invalid userId: ${userId}`);
continue;
}
const currentLyraData = playerStore.getAsync(player);
if (currentLyraData && currentData !== currentLyraData) {
playerStore.updateImmutableAsync(player, () => currentData);
}
}
}
});

export function loadPlayer(player: Player) {
playerStore.loadAsync(player);
const data = playerStore.getAsync(player);
if (data) {
PlayerDataAtom((prev) => ({
...prev,
[player.UserId]: data,
}));
}
}

export function unloadPlayer(player: Player) {
PlayerDataAtom((prev) => {
const newData = { ...prev };
delete newData[player.UserId];
return newData;
});
playerStore.unloadAsync(player);
}

export const getPlayerData = (userId: number): PlayerData | undefined => PlayerDataAtom()[tostring(userId)];

export const updatePlayerData = (player: Player, callback: (data: PlayerData) => PlayerData | false): Promise<boolean> =>
playerStore.updateImmutable(player, callback);
export interface PlayerData {...}

type PlayerDataMap = {...}

export const PlayerDataAtom = atom<PlayerDataMap>({});

const playerStore = createPlayerStore<PlayerData>({
...,
changedCallbacks: [
(key: string, newData: PlayerData) => {
PlayerDataAtom((prev) => ({
...prev,
[key]: newData,
}));
},
],
});

subscribe(PlayerDataAtom, (newData, oldData) => {
for (const userId in newData) {
const currentData = newData[userId];
const previousData = oldData?.[userId];

const userIdNumber = tonumber(userId);

if (!userIdNumber) {
warn(`Invalid userId: ${userId}`);
continue;
}

if (currentData && currentData !== previousData) {
const player = Players.GetPlayerByUserId(userIdNumber);
if (!player) {
warn(`Invalid userId: ${userId}`);
continue;
}
const currentLyraData = playerStore.getAsync(player);
if (currentLyraData && currentData !== currentLyraData) {
playerStore.updateImmutableAsync(player, () => currentData);
}
}
}
});

export function loadPlayer(player: Player) {
playerStore.loadAsync(player);
const data = playerStore.getAsync(player);
if (data) {
PlayerDataAtom((prev) => ({
...prev,
[player.UserId]: data,
}));
}
}

export function unloadPlayer(player: Player) {
PlayerDataAtom((prev) => {
const newData = { ...prev };
delete newData[player.UserId];
return newData;
});
playerStore.unloadAsync(player);
}

export const getPlayerData = (userId: number): PlayerData | undefined => PlayerDataAtom()[tostring(userId)];

export const updatePlayerData = (player: Player, callback: (data: PlayerData) => PlayerData | false): Promise<boolean> =>
playerStore.updateImmutable(player, callback);
is this good the ... is for discord character limit
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
uhh kk Is that like a package I need to download
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
lyra is fine I just bullied him I dont use lyra mostly because I think my datastore library is the last thing I want to be the source of truth
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
it just doesnt align with my workflow currently and I dont think it ever will not saying I wouldnt use it but its always the main drawback if I use jecs I want to keep everything in the world
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
if I use charm/reflex, I want to keep mutations strictly with dispatchers so my code is more predictable no if a server fails its just not gonna save the progress since last save I dont think its a big deal if the autosave is every minute, its just a minute of progress
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
thats why you process those differently and/or force a save before confirming the purchase
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
:hii: hi guys im back :catsmile: lemme read all of this rq
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
same thats why im using it I think i might just not use charm for playerdata and just sync the data manually
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
basically so just manually syncing would be way simpler but ima use charm for other state just not player data
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Jolly Pizza
Jolly PizzaOP•4mo ago
ig :shrug: but then what happens when i update the data in the atom this is what i currently have it syncs both ways but like what do i do if the update fails for lyra do i revert the atom in the subscribe
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
mergeDeep /= dispatchers
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
at all at that point just send the new data to the client entirely
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
its not the same as dispatchers, you cant do mergedeep because it will clone things you dont want to Im not saying transactions are useful but the way I see it, datastores are asyncronous, error prone, hard to work with which is both the main reason why you would want them as the source of truth, so no dupes or unsaves progress but at the same time its why its a terrible idea to make this the source of truth in code
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41•4mo ago
again, its not how I approach state if you find transactions useful sure but now specially using jecs good luck syncing an entire inventory with lyra
Jolly Pizza
Jolly PizzaOP•4mo ago
I should rename this to lyra discussion šŸ™
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?