Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kingdutka · Sep 18, 2011 at 07:13 PM · c#androidjavascript

Need Help - Last Problem Converting PC to Android - Using JS to read CS

I managed to fix all of my code that was conflicting with Android specific rules (dynamics vs static, etc). All but one that is...

I am not good with C# (..yet) so all my scripts are done in JS. All but one that is...

I have a C# script that uses the built in serialization to save/load my 'game saves'. I have a couple JS files that allow me to interact with the C# file. See the following link for full details:

http://forum.unity3d.com/threads/94997-Need-Help-Save-Load?p=619994&viewfull=1#post619994

Everything was working great in the PC/Mac version but I am having a problem with Android. If I could just get this one chunk working, I will understand how to fix the rest.

 if(firstRun){
             firstRun = false;
             var script = GameObject.Find("Level").GetComponent("SaveAndLoad");
 
             //Slot 1
             script.SendMessage("Load","./saves/SaveData_1.agt");
             saveInfo[0] = GameObject.Find("Level").GetComponent.<LoadData>().data;
 
             //Slot 2
             script.SendMessage("Load","./saves/SaveData_2.agt");
             saveInfo[1] = GameObject.Find("Level").GetComponent.<LoadData>().data;
 
             //Slot 3
             script.SendMessage("Load","./saves/SaveData_3.agt");
             saveInfo[2] = GameObject.Find("Level").GetComponent.<LoadData>().data;
 
             //Slot 4
             script.SendMessage("Load","./saves/SaveData_4.agt");
             saveInfo[3] = GameObject.Find("Level").GetComponent.<LoadData>().data;
 
             //Slot 5
             script.SendMessage("Load","./saves/SaveData_5.agt");
             saveInfo[4] = GameObject.Find("Level").GetComponent.<LoadData>().data;
 
             //Slot 6
             script.SendMessage("Load","./saves/SaveData_6.agt");
             saveInfo[5] = GameObject.Find("Level").GetComponent.<LoadData>().data;
 
             //Debug Info
             for(var i=0; i<saveInfo.length; i++){
                 **Debug.Log("SlotSelection caching "+i+": "+saveInfo[i].levelReached);**
             }
         }

The error I am getting is:

Assets/Scripts/MainMenu/SlotSelection.js(47,71): BCE0019: 'levelReached' is not a member of 'Object'.

"levelReached" is a public variable defined in the SaveAndLoad.cs file. It is included with other variables and "packed up" into a single variable called "data". I'm not sure exactly how it works but the C# code looks like this:

 **data = (SaveData)bformatter.Deserialize(stream);
 GameObject.Find("Level").SendMessage("LoadData",data);**

If anyone can help me get the "levelReached" value out of "data", I can fix all the rest of my problems and finally test this thing....

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kingdutka · Sep 19, 2011 at 12:44 AM 0
Share

Note:

This is at the top of the "SaveAndLoad.cs":

public class SaveData : ISerializable { // === Values ===

 // Edit these during gameplay

 public int month = 1;

 public int day = 1;

 public int year = 2011;

 public string time = "12:00:00";

 public int levelReached = 0;

 public float completionPercent = 0.0f;

...

And yet I cannot use "SaveData" as a type such as:

var saveInfo = new SaveData[5];

avatar image kingdutka · Sep 19, 2011 at 01:21 AM 0
Share

$$anonymous$$aybe I am over complicating this??

I'm just trying to pass the "data" variable from the C# file to the JS file, then have a different JS file get one of the values out of the "data" variable from the first JS file. ie: data.levelReached, data.completionPercent, data.time, etc

When I try something like "print(data.levelReached)" I get an error about "levelReached" not being a member of "object". In the PC build, there was no error and the console/debug window said "1" letting me know I had reached level 1...

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by kingdutka · Sep 19, 2011 at 02:25 AM

The problem was partly answered by Warwick's post but one thing that I was also missing... The C# file was in the same folder with the JS files. I read that they cannot be loaded/executed at the same time and one needs to be in the "Standard Assets" or "Plugins" folder. I moved the C# script to the standard assets folder and I am now able to access "SaveAndLoad" and "SaveData" as a valid 'type' and as such, I can now do:

var saveInfo = new SaveData[5];

And voila, almost every single error I had just disappeared (now to replicate to the other files as needed and I'm done!)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Waz · Sep 18, 2011 at 11:28 PM

Your saveInfo variable is declared wrong. My guess is it is:

 var saveInfo = new Array();

when it needs to be:

 var saveInfo = new LoadData[5];
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kingdutka · Sep 19, 2011 at 12:37 AM 0
Share

I tried that and it only changed my error from:

Assets/Scripts/$$anonymous$$ain$$anonymous$$enu/SlotSelection.js(47,71): BCE0019: 'levelReached' is not a member of 'Object'.

To:

Assets/Scripts/$$anonymous$$ain$$anonymous$$enu/SlotSelection.js(47,71): BCE0019: 'levelReached' is not a member of 'LoadData'.

Please note that it was working "as is" on PC/$$anonymous$$ac. It only stopped working when I switched to an Android environment...

avatar image Waz · Sep 19, 2011 at 03:35 AM 0
Share

Sorry, scrolling error by me. I didn't see the .data

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

I need help with a script(brauche hilfe mit einen Script) 0 Answers

Objectives based on object appear. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges