This site requires JavaScript, please enable it in your browser!
Greenfoot back
444Jam444
444Jam444 wrote ...

2020/5/29

Act method causing error in switch statement (getKey())

1
2
3
4
5
6
danpost danpost

2020/6/3

#
4444Jam4444 wrote...
I still don't understand why a multi-line comment was involved in a terminal error message?
Maybe it was from a previous run where those line or lines actually had code in them. Next time, clear the terminal output and recreate the error to be sure what lines are referred to.
4444Jam4444 4444Jam4444

2020/6/4

#
I'm pretty sure it's to do with some botched regex. I had a similar thing happen today where the terminal highlighted an empty line. I scrolled up past the error message to see another error message referring to regex. "Unclosed character: currentCalculation.replaceAll("\\Q I'm trying to replace any instances of "
4444Jam4444 4444Jam4444

2020/6/4

#
It seems that I'm having difficulties posting this comment because of the use of square parenthesis. I have copied the above comment, but replaced all square brackets with {} The above comment is supposed to read: I'm pretty sure it's to do with some botched regex. I had a similar thing happen today where the terminal highlighted an empty line. I scrolled up past the error message to see another error message referring to regex. "Unclosed character: {.{" or something. I understand why that message was popping up, but I don't know how to fix it.
currentCalculation.replaceAll("\\Q[\\E\\.\\Q[\\E","\\Q[\\E");
I'm trying to replace any instances of "{" + any char + "{" with just "{" (and the same for }) but that's difficult because it requires regex's "." but at the same time, regex doesn't like searching for meta-characters in strings. I tried to get around this by using "\\Q" + char + "\\E" to make regex treat {} as a non-meta-character, but apparently the code just completely ignored that attempt; terminal showed "{.{". Do I have to group the regex by using ()?
4444Jam4444 4444Jam4444

2020/6/4

#
Follow up question: If I make a static class for storing information, can non-static variables from other classes be stored as a static variable within the static class and vice-versa? Because I have just come to the realisation that, if the user wishes to add a (mathematical) constant into the calculation, the world must be switched, so the user's calculation would be wiped (at least I'm pretty sure it will be, let me know if I'm wrong). Will transferring the calculation to a static class right before switching worlds (and transferring back) solve this issue? Or will it throw an error relating to static vs non-static?
danpost danpost

2020/6/4

#
4444Jam4444 wrote...
if the user wishes to add a (mathematical) constant into the calculation, the world must be switched, so the user's calculation would be wiped (at least I'm pretty sure it will be, let me know if I'm wrong).
Nothing should change (or be wiped) in your world if you go back to that same instance of world (do not use "new WorldClassName()".
danpost danpost

2020/6/4

#
As far as the regex issue, you will need to show the class codes and point to the problem area.
4444Jam4444 4444Jam4444

2020/6/4

#
danpost wrote...
Nothing should change (or be wiped) in your world if you go back to that same instance of world (do not use "new WorldClassName()".
I do, in a way, have to use "new worldName" because I need to clear the display. Unless it's possible to switch worlds without using 'new' while also clearing the display? Am I wrong in thinking that the world is replaced when switching worlds? Because all the objects belonging to the world disappear...
4444Jam4444 4444Jam4444

2020/6/4

#
danpost wrote...
As far as the regex issue, you will need to show the class codes and point to the problem area.
I'll have to deal with it later. As far as I'm concerned, past-me is an idiot who throws in unnecessary lines of code to prevent things that will likely never happen before even programming in the modules that past-me is error preventing for. (I'm joking, but it's accurate and a bad habit) Edit: Forgot to mention that after moving the regex to a comment, I have been error/exception-free in each (brief) test I've conducted.
danpost danpost

2020/6/4

#
4444Jam4444 wrote...
I do, in a way, have to use "new worldName" because I need to clear the display. Unless it's possible to switch worlds without using 'new' while also clearing the display? Am I wrong in thinking that the world is replaced when switching worlds? Because all the objects belonging to the world disappear...
You can only have one world active at a time. However, multiple worlds can still exist at one time. Please post the code of this "static" class.
555JAM555 555JAM555

2020/6/4

#
Hi danpost, it has happened again. This time, I made sure that there were zero external links. I was just posting the code for each of my static classes (4 total). This is extremely frustrating. I apologise, but I really need to vent my frustrations. On a website made for posting code to ask for help, it is possible to have permissions to post suspended for posting code and asking for help. This project is due in a week, and I have so much more to do. I'm really sorry, but I'm so overtired from numerous 13 hour days of work. Anyway, rant out of the way, what I posted was (this is the edited version that I made as soon as my comment went under review):
danpost wrote...
Please post the code of this "static" class.
I was speaking theoretically, I haven't actually made the static class I was referring to. Just to be sure that I haven't mistaken what you mean, here are all my static classes: <Code Omitted> So I have updated the uploaded scenario, the static classes are Variable, Constant, Calculations, SolutionSteps
danpost danpost

2020/6/4

#
555JAM555 wrote...
Hi danpost, it has happened again. This time, I made sure that there were zero external links.
Except that in the middle of the try block in your Variable class constructor, you blatantly show a link. Same is for your Constant and Calculations classes.
danpost danpost

2020/6/4

#
4444Jam4444 wrote...
I do, in a way, have to use "new worldName" because I need to clear the display. Unless it's possible to switch worlds without using 'new' while also clearing the display?
From where (class & method, with what world active) and to which world is this referring to?
555JAM555 555JAM555

2020/6/4

#
danpost wrote...
Except that in the middle of the try block in your Variable class constructor, you blatantly show a link. Same is for your Constant and Calculations classes.
How'd I miss it? I'm just so tired... My original comment is still under review after >6 days. It's completely unintentional, I'm trying my best. It doesn't seem right that my account can be held hostage for something that I didn't know was a thing and wasn't made clear in the "Posting code? read this!" page. Surely you can do something about this? I won't, from now on, post code from this project. Instead, I'll update the scenario I've uploaded so that I don't accidentally post external links. The only reason I have external links in my code is because those are the sites I used for quick help, and I don't have the time to do intrinsic documentation so I try to use the site links (from the sites that helped me) as a substitute for internal documentation...
danpost danpost

2020/6/5

#
555JAM555 wrote...
It doesn't seem right that my account can be held hostage for something that I didn't know was a thing and wasn't made clear in the "Posting code? read this!" page. Surely you can do something about this?
How?
555JAM555 555JAM555

2020/6/6

#
If you aren't able to do anything, then that's fine, you've been a great help so far, and I really appreciate it. It's more important now that I just move past this issue (for now) and get this project out of the way. It's been quite frustrating, but I've calmed down now and realised that I'll only get less done by making a fuss about this before I get everything done. With that out of the way, I'd like to say that I'm having an issue with button images. What I'm trying to do (as per my documentation) is make the calculator buttons change image when they become invalid, depending on where the user's cursor is. The issue is that the buttons decide to vanish 1 by 1 when clicked. I'm theorising that the method within button class only works for individual objects of button, and that (due to bad temporary design choices made earlier on in the implementation) the second image for each button is just not a button (or it could be some coding flaws - I haven't looked into it that much because I've got sleep and other work on my plate). Strangely, the number buttons should not be disappearing though, unless something is causing them to become invalid? It could be relating to currentIndex, getChar() (in Calculate), or my use of multiple case conditions for 1 result in switch;
BEGIN if_a_or_b_or_c
    switch(varName){
        case a:
        case b:
        case c:
            //do stuff
            break;
        default:
            break;
    }
END if_a_or_b_or_c
Is that the correct way of doing multiple cases for a single process? (See button class: img2, image2, checkValidity, etc; Calculate class: checkValidButtons (unfinished) )
There are more replies on the next page.
1
2
3
4
5
6