Unfixable code??? GUI error

Edit : Deleted

Your code seriously needs to have your data tucked away in arrays and treated by loops. I suggest you read some more on those two concepts: arrays and loops.

oh my!

I think that error will occur if you have mismatching GUI Begin’s and End’s. I suggest commenting out blocks of code to narrow down where the problem occurs - partitioning the code into more functions may make that easier.

I have used them before but I wanted to get the base concept down before that this code took me 2 hours to write. But I will turn it to arrays though it will be hard for me though because I normally use functions not arrays though!!

Easy way to do this is to read a list of parameters instead of each of them individually

if (ship1 == true)
{
shipname = PlayerPrefs.GetString("ship1name");
bodyturningStats = PlayerPrefs.GetInt("1bodyturning");
bodySpeedStats = PlayerPrefs.GetInt("1bodySpeed");
bodystrengthStats = PlayerPrefs.GetInt("1bodystrength");
bodytricksStats = PlayerPrefs.GetInt("1bodytricks");
wingturningStats = PlayerPrefs.GetInt("1wingturning");
wingSpeedStats = PlayerPrefs.GetInt("1wingSpeed");
wingstrengthStats = PlayerPrefs.GetInt("1wingstrength");
wingtricksStats = PlayerPrefs.GetInt("1wingtricks");
engineturningStats = PlayerPrefs.GetInt("1engineturning");
engineSpeedStats = PlayerPrefs.GetInt("1engineSpeed");
enginestrengthStats = PlayerPrefs.GetInt("1enginestrength");
enginetricksStats = PlayerPrefs.GetInt("1enginetricks");
}

you probably have data like this:

ship1name=ship1
1bodyturning=10

etc.

Instead you could do:

shipname;bodyturning;bodySpeed:… (titles)
ship1;10;20;… (data for ship1)
ship2;11;18;… (data for ship2)

etc.

Then do:

var shipData : Array = row.Split(";"[0]);

…for each row… (edit: in a loop!)

Best thing, if you go this way is that you can create your data in spreadsheet and export as .csv (txt -file)

Anyway, I highly recommend studying bit more…

edit2: I hope this is a joke…

Here is my real code and the suggestion you made really isn’t possible I don’t think (I’m not sure (I specialize in C++ java lang not java script) also CSS HTML.

Any suggestions are welcome and if any code you need or to to converted to I will do it for u for free as long as I’m in credits (commercial) noting for non-commercial

(here is what to put in commercial - Some Code by Alex Turner - Unity 3d - Amazing Coder)

k

Eidt: Deleted

For the sake of your own sanity (not to mention other peoples’ :wink: ), I’d suggest learning about loops, arrays, and data structures. A glance at that code tells me it’s about 100X too big, in any language, Javascript or otherwise. It’s not reasonably possible to maintain or extend code like that, never mind trying to figure out what’s wrong.

–Eric

General note:
When the forums cut off part of your pasted code, you should probably not post it and you should reconsider your code design.

Regarding your current issue:
I am pretty certain that nobody will take the time to read through your code and address your problem at hand before you redesign it - making it more readable.

ok sure I will then re post it ok!

is 1609 lines good because I can’t reduce it down to below that and my goal is 700 max. Please say ou’ll help me aleast make my code smaller because this si central to my game I am working on (similar to racing gams and being able to customize ships and or cars is a really nice feature)

please help me plz

900??? lines of code

One thing you need to learn to do is to generalize. If you have a long string of if/else/if/else, you’re almost certainly doing something wrong.

For example, in your GetColor and SetColor functions, you have

	if (Color == Color.black)
		colorString = "black";
	else if (Color == Color.red)
		colorString = "red";
	else if (Color == Color.green)
		colorString = "green";

and so on. But why store the data as a name at all? If you can store data simply as 3 numbers, you can do this in only a few lines of code. (Ironically, you seem to have found this, but tried to do it with three int’s - if you read the Color documentation you’d see that the values of r g and b are floats from 0 to 1) Also, as has been hinted, you should look into learning how to put together and parse strings. Storing one piece of data (the color) across three variables is asking for problems. So instead, you might do something like this:

function SetColor(name : String, col: Color) {
PlayerPrefs.SetString(name, col.r+","+col.g+","+col.b);
}

function GetColor(name : String) : Color {
var str : String = PlayerPrefs.GetString(name);
var split : String[] = str.Split(","[0]);
if (split.length == 3) { //probably means we have a valid string
var r : float = float.Parse(split[0]);
var g : float = float.Parse(split[1]);
var b : float = float.Parse(split[2]);
return Color(r,g,b);
}
else {
return Color.black;
}
}

That’s an example of how to save and load any kind of data; you could expand on it (for example, nest many comma-separated strings within one semicolon separated strings, and many of those in a newline-separated string) to save all the data for your customized craft in one string.

Another thing I see a lot of is various utility functions from the wiki. these should be in an auxiliary file and called from there; for example, put Bounce in Mathfx.js and call Mathfx.Bounce.

also:

import UnityEngine.Debug;
import System;
import System.Text;
import System.Security.Cryptography;

I could have missed something but I’m pretty sure you’re not using any of those, and they’ll balloon your build size.

These should get you started in shrinking your code.

here is my code with the problems

The only reason in X why there r wiki scripts in javascript is because I don’t like having to put theat stuff in my script

(math script name)x.bounce

vs

x.bounce

much simpliar saves alot of time if added up

so here is my script in attachment