Thalassicus
Bytes and Nibblers
Moderator Action: ATTENTION, please see post #3 in this thread for the SQL information .
Anyone have tips for writing loops in sql? I've always struggled to translate even simple algorithms like the one below. I eventually manage, but it takes me an unusually long time compared to other code formats.
"For each resource Moai can improve, copy the yields from the normal improvement for that resource."
It's easy to write in lua pseudocode...
When I try to translate that to nested sql select statements, my mind gets turned around into spaghetti.
Does anyone know a good starting point? Would it be easier to start at the innermost loop and work outwards... or outer loop inwards? Is there a general pattern you follow for writing loops in sql?
Anyone have tips for writing loops in sql? I've always struggled to translate even simple algorithms like the one below. I eventually manage, but it takes me an unusually long time compared to other code formats.
"For each resource Moai can improve, copy the yields from the normal improvement for that resource."
It's easy to write in lua pseudocode...
PHP:
for _, impType in pairs({'IMPROVEMENT_MOAI'}) do --table allows scalability
for impResourceInfo in GameInfo.Improvement_ResourceTypes{ImprovementType = impType} do
for impYieldInfo in GameInfo.Improvement_ResourceType_Yields{ResourceType = impResourceInfo.ResourceType} do
if not GameInfo.Improvements[impYieldInfo.ImprovementType].CreatedByGreatPerson then
INSERT INTO Improvement_ResourceType_Yields
(ImprovementType, ResourceType, YieldType, Yield)
impType, impResourceInfo.ResourceType, impYieldInfo.YieldType, impYieldInfo.Yield
end
end
end
end
Does anyone know a good starting point? Would it be easier to start at the innermost loop and work outwards... or outer loop inwards? Is there a general pattern you follow for writing loops in sql?