edited July 2015 in Makinom Scripting
dont know where else to ask this but im wondering how to set info to a struct from another C# script kinda need to do this in order to get things rolling again so any one with any info on this would be great
Post edited by wtyson on
new website can be found here http://www.fore-loregames.com

Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games

or check out the face book page here https://www.facebook.com/ForeLoreGames
  • edited July 2015
    mainly just need to know how to find the index of something with in a struct... heres a sample of the code im working with . public struct Weapons
    {
    public bool available;
    public WeaponType type;
    public WeaponBase weapon, subWeapon;
    public Rigidbody dropout;
    }

    public int maxWeapons = 2;
    public AudioClip switchWeapon, switchShootingMode, subWeaponOnOff, switchProjectile;
    public GameObject newwep;
    public Weapons[] weapons;




    and lower theres

    for( int cnt = weaponIndex; cnt < weapons.Length; cnt++ )
    if( cnt != weaponIndex && weapons[ cnt ].available )
    {
    weaponIndex = cnt;
    StartCoroutine( ChangeWeapon() );
    break;
    }


    my problem is i cant seem to figure out how to grab anything from the index
    Post edited by wtyson on
    new website can be found here http://www.fore-loregames.com

    Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games

    or check out the face book page here https://www.facebook.com/ForeLoreGames
  • Accessing data in a struct is the same as in a class.

    What do you want to do/access in the struct?
  • edited July 2015
    basically im trying to set a game object in the struct at its index when i spawn the wep with ork but im having a hell of a time figuring it out if you got time an are willing mind taking a look at the code below an see what you think? the wepaonbase is what im trying to set at run time

    Deleted
    Post edited by wtyson on
    new website can be found here http://www.fore-loregames.com

    Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games

    or check out the face book page here https://www.facebook.com/ForeLoreGames
  • Wild guess - your weaponIndex is set to -1 in the Awake function, usually next would be the Start function, where you use it to set cnt, which indexes the array, which will cause an out of bounds exception (i.e. tries to access weapons[-1]).
  • so basically everything would have to be set at the -1 index?
    new website can be found here http://www.fore-loregames.com

    Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games

    or check out the face book page here https://www.facebook.com/ForeLoreGames
  • No, every array goes from 0 to array.Length-1 > everything outside of that range will throw an error.
    You'll need to start at index 0.
  • edited July 2015
    yeah i been trying to write a script to do this but i keep getting out of range no matter what i set it to weather it be -1 or 0 or 1

    Deleted


    i need to place it at ta certain index so not sure how to go about it
    Post edited by wtyson on
    new website can be found here http://www.fore-loregames.com

    Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games

    or check out the face book page here https://www.facebook.com/ForeLoreGames
  • ok so after a long bout of messing with this stupid thing finally wrote a script to make it work problem was he has everything set to private that delt with the weapons array so after i figured that out i was able to get it to work like i wanted -_- just sucks that it took this long to figure out... so thanks gil for looking at a non ork script and giving me some advice on it
    new website can be found here http://www.fore-loregames.com

    Follow the game Development on Twitter https://twitter.com/Fore_Lore_Games

    or check out the face book page here https://www.facebook.com/ForeLoreGames
Sign In or Register to comment.