what is wrong in here <https://trycf.com/gist/be3f...
# cfml-general
g
what is wrong in here https://trycf.com/gist/be3f8fed1d5d9c45aca1498f947556c5/lucee5?theme=monokai why its not going into the session.original code to count the session.orginal
v
<cfdump var="#isDefined("session.original")#">
g
i did placed a dump, but what's going wrong in there
tried like this same issue original not found
Copy code
<cfset session.original = 1>
<cfloop collection="#session#" item="i">
	<cfif left(i, 8) is 'original'>
		<cfset i['sessionRotated'] = structCount(i.original)>
		<cfset i['original'] = ''>
	</cfif>
	<cfset SetVariable("ix.session.#i#",duplicate(session[i]))>

</cfloop>
<cfdump var="#ix#">
s
I'm getting errors trying to run that tryCF; did you actually run it? At a glance, Viral is right, though. you've got "isDefined ('original')", but that variable doesn't exist, it's session.original.
g
i defined at the top and looping over a collection, so it should find it
s
1. did you try actually running the cftry you posted? 2. did you TRY making it session.original instead of just original?
1
g
yes i tried running different varitions, even i did not saved all of them as gists but it seems none worked
m
What are your original intent? Currently this code loops over all items in the session collection (not just original) and checks to see if a unscoped variable of original exists if it exists does some stuff with it and something called i.original but I is a string because you are looping over the collection session..... then it tries to run setVariable to a string that begins with i. if i remove the i. and the last dump at least your code runs, but I don't think it is going to be doing what you think it is going to be doing. Start off by writing out your code in logical pseudocode and then transform it into actual code a bite at a time.
g
original intent => if session.original exists, just do a struct count session.original as to how many times it happened, because session.original itself is a complex structure and instead of displaying it, i just want it to be counted how many times it happened
v
how many times it happened
What
m
Well your first line of code makes session.original a numeric/string... so you need to Check to see if original is in Session StructKeyExists(Session, "original") and IsStruct(session.original) then count members StructCount(session.original)
g
so did a modification like this
Copy code
<cfset session.original = { 'id' = 1}>
<cfloop collection="#session#" item="i">
	<cfif StructKeyExists(i,'original') and isStruct(i.original)>
		<cfset i.sessionRotated = structCount(i.original)>
		<cfset i.original = {}>
	</cfif>
	<cfset SetVariable("id.session.#i#",duplicate(session[i]))>

</cfloop>
<cfdump var="#id.session#">
still geting an issue
s
Again, are you actually RUNNING that in TryCF? I'm still getting syntax errors when trying to.
m
when you are looping over a collection you are getting the keyName and not the keyValue so i is a string right here...
in your case i would take small bites and make each step of your problem work successfully before adding anything more in... you seem to be getting confused on some basic stuff.
g
this is too annoying i did a dump of <cfdump var="#isStruct(i)#"> inside a loop and its going as false
seems i am all fried why can't this simple session is not freaking solve up
m
yes because it is a string
a
Read the docs for a collection loop...
Don't ever write code you don't understand.
Also... if you checked the value of
i
when it didn't work how you expected it, you'd likely have worked it out for yourself.
g
@Adam Cameron please don;t start again
😕 1
a
Don't start what?
g
i am already trying so you can't say read the docs all the time
i know what i am doing
a
Don't start... suggesting you troubleshoot your own work a bit, instead of asking other ppl to do it?
m
@gsr it is quite obvious you don't, but that is ok that is the first step is to admit that and then find your solution.. We all began some where.
2
g
did i asked other to do my work, i am asking what i am doing wrong and if someone is guiding why you have an issues, please ignore if you can't help
a
Yes, you are very much asking other ppl to do your work for you.
this is too annoying
i did a dump of <cfdump var="#isStruct(i)#"> inside a loop and its going as false
That is literally asking other ppl to do your work for you.
g
ok stop, i don't an answer from anyone, please go away
i will do myself,
a
Don't throw yer toys.
😂 1
Just... read the docs for
<cfloop>
... and check the value of
i
. What does that tell you?
ie: ask yourself why
isStruct(i)
is returning
false
. Why might it do that? First step: "well if it's not a struct... what is it?" Go check. Troubleshooting. This is what we all do all day every day.
m
And for your problem @gsr there is no need for a loop at all if what you said your problem was then cnt = -1 if ( StructKeyExists(session, "original") and IsStruct(session.original) ) { cnt = StructCount(session.original) } cnt would then have your value
g
@Michael Schmidt i fixed, i had to put that outside the loop and it worked, i told already due to overwork, i was also fried up and unable to perform a simplistic issue, but after rest, it was easy though Some people will keep on thinking that others do not know anything and simply divert to cfdocs. Adam no personal comments, but it seems you are quite _ve when the approach comes to cfml and its functions, at the end its all objctive and only thing it matters is code
a
Glad you got it sorted. What did the correct code look like? There is nothing wrong with suggesting ppl read the docs about the code they are having problems with if it's abundantly clear they haven't read the docs, because the lack of doing so is what's causing their issues in the first place. Be honest... you weren't familiar with how a collection loop works, were you? Do you think that when the code didn't work you had gone "oh... hang on... this isn't doing what I expected... am I sure I am using this right? What do the docs say on this?" you'd likely have been able to solve your own problem? Don't be reactive to that. Be honest. Equally suggesting troubleshooting steps to engage in before asking for help is... simply good advice, and a reminder of what you should be doing.
isStruct(i)
is false? Why? What's the value of
i
if it's not a struct? Once you have that value, you can reason as to why it's that value. Simple troubleshooting. Your overall issue I think is that you are relying on asking other people to help you too early in the troubleshooting cycle. As soon as something isn't working how you expect it to: you ask here (or: this is how it seems). That is too soon. Troubleshoot first. Make sure you know what the code you are using is supposed to do (ie: read the docs / refresh your memory / whatever). When code is not doing what you expect... inspect the values. You need to do all this sort of thing before escalating it to other people. This is not me being a meany. This is me observing what the baseline of troubleshooting is, which is fundamental to our jobs.
💯 1
s
I'm also curious what the correct code looks like.
g
Still you are going in wrong direction, eventually timezone differs where i work and i was working whole day when i reached this problem, i was so tired that i gave up eventually which is simple problem for me to fix when i am fresh, so talking about loops, i know that and i do not need to explain to anyone how that works. what it is a structure or array or whatever. so in the end, i just asked, lets see if someone can point me what i am doing wrong in the code instead of asking people, hey guys, please solve my problem, because i do not know how loop works. i solved it on my own, its simple. you might not ask questions because you think you knows everything ColdFusion offers and you are here to help. so good for you, for me its a platform when a person is stuck on a code the peers who knows how code works should guide and that is exactly what slack is doing you are going off direction here.
s
I'm asking a question: What does the corrected code look like? What fixed it?