Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need basic string to float answers - School Project = URGENT

Discussion in 'Scripting' started by Hunter_W, May 5, 2014.

  1. Hunter_W

    Hunter_W

    Joined:
    May 5, 2014
    Posts:
    57
    Hey, this is my first time posting on the forums. I am having a problem with an equation in my script for a project due later today... I'm SO CLOSE! Am I using float.parse correctly????????

    I am creating a personal app and need this formula as one variable(mdot) for another formula. I am basing all of this off of User inputs from GUI Textfields, so my variables should be pretty self explanatory and that is also why I have to Parse. Why am I getting this error? I know for sure that the error is in this snippet. [I've seen this error in other posts, but I still don't know what it means.]

    Here is the error: It is not possible to invoke an expression of type 'int'.
    Error #: BCE0077

    Variables read: var x : String = "";

    Code (csharp):
    1.  
    2. mdot = ((float.Parse(As) * (float.Parse(pt))) / (Mathf.Sqrt( float.Parse(Tt))) * (Mathf.Sqrt(( (float.Parse(gam)) / (float.Parse(R)) ))) * ((( (float.Parse(gam)) + 1) / 2) ^ (((( (float.Parse(gam)) - (float.Parse(gam)) ) - (float.Parse(gam)) ) + 1) / (2((( (float.Parse(gam)) - (float.Parse(gam)) ) - (float.Parse(gam))) - 1)))));
    3.  
    (This is a formula for rocket thrust taken from NASA)

    It looks to me that everything is in place (editor says so). What's the easy fix?:confused::eek:

    Could you also tell me how to change the name of, and delete threads for the future (I posted this 1 2x)?
     
  2. Hunter_W

    Hunter_W

    Joined:
    May 5, 2014
    Posts:
    57
    I tried setting everything to an int with a value of 1. I then removed the Parse functions and am still getting the error. ANY ADVICE HELPS!
     
  3. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    This is wrong:
    Code (csharp):
    1.  (2((( (float.Parse(gam))
    Change to:
    Code (csharp):
    1.  (2 * ((( (float.Parse(gam))
    As a side note: if a single line in your code exceeds 120 character, it's probably a good idea to try and break it down into smaller steps across more lines. There shouldn't be a performance penalty because any half-decent compiler will optimize it away.

    Another note on the other side: Using the words "urgent" and "ASAP" in a forum post usually has the opposite effect :)
     
    Last edited: May 5, 2014
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,952
    Your problem is here:
    Code (csharp):
    1.  
    2. (2((( (float.Parse(gam))
    3.  
    With the parens after the 2 you are effectively trying to treat an in as a function. 2(); No idea what is supposed to be, but that isn't valid.
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Plus, when the compiler tells you that there's an error, it tells you what line it's on. If everything is one one line, knowing that the error is on that line doesn't really help you narrow it down...
     
  6. Hunter_W

    Hunter_W

    Joined:
    May 5, 2014
    Posts:
    57
    THANK YOU GUYS SO MUCH! Sorry for "Urgent" it's due in a few more hours so... xD
     
  7. Hunter_W

    Hunter_W

    Joined:
    May 5, 2014
    Posts:
    57
    Wait! Nope, still a problem. It's probably a really easy fix, how would I insert an exponent? I am getting an error that "^" can't be used with floats.
     
  8. gruddlebug

    gruddlebug

    Joined:
    Mar 11, 2013
    Posts:
    65
    Hello,

    I think you need Mathf.pow(a, b);

    as ^ is exclusive-or in Unity Script
     
    Last edited: May 5, 2014
  9. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Code (csharp):
    1. Mathf.Pow()
     
  10. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Sure, but when were you given the assignment?

    I have a hunch that you'd have had plenty of time to ask these questions in a non-urgent manner if you'd got up to this part with more time to spare. ;)

    It's actually a really important lesson when making software. You'll commonly hit problems that you didn't foresee, because a huge amount of software engineering is about problem solving - if there was an off-the-shelf solution you wouldn't have to program something in the first place, right? So whenever you plan something, make sure you've got time up your sleeve!
     
  11. Hunter_W

    Hunter_W

    Joined:
    May 5, 2014
    Posts:
    57
    Thanks guys! And sorry, I can't not procrastinate.

    What's the fun in that?
     
    Last edited: May 5, 2014
  12. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    I have more faith than that. I suggest trying different strategies to encourage yourself to not procrastinate. Generally speaking, if you set achievable short term goals that are bite sized you'll find it far easier. If your brain can see all the way to the end of something in detail it's easy to get started, where if you're trying to figure it out it's really hard.

    So even just "all I'm going to do today is set up the Visual Studio project and scribble down a quick design concept". That's 15 minutes, right?

    Then tomorrow "I'm going to stub in the classes from that design concept". What's that, 10 minutes for the typical assignment?

    Then "I'm just going to make this small piece work, which I think will go something like...". That's probably a bit longer, but you've got momentum now. It's way easier when you're not starting from nothing.