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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Pass to binary

Discussion in 'Scripting' started by Kainanteh, Apr 9, 2015.

  1. Kainanteh

    Kainanteh

    Joined:
    Sep 3, 2014
    Posts:
    14
    The error is: the * or -> operator must be Applied to a pointer

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Automatav1 : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.  
    9.     }
    10.  
    11.     // Update is called once per frame
    12.     void Update ()
    13.     {
    14.  
    15.  
    16.  
    17.     }
    18.  
    19.     //Funcion para pasar de decimal a binario
    20.     public unsafe int pasar_a_binario(int num,int[] array,int cont)
    21.     {
    22.  
    23.         if(cont==0)
    24.         {
    25.      
    26.       return *array; //The error here
    27.  
    28.         }
    29.         cont--;
    30.         array[cont]=num%2;
    31.      
    32.  
    33.         if (num == 0)
    34.         {
    35.  
    36.         return 0;
    37.  
    38.         }
    39.         else
    40.         {
    41.          
    42.         pasar_a_binario(num/2,array,cont);
    43.      
    44.         }
    45.  
    46.     }
    47.  
    48. }
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    get rid of the * on line 26?
    You shouldn't be trying to return an array from an int method though
    not sure about using pointers in unity c#
     
  3. Kainanteh

    Kainanteh

    Joined:
    Sep 3, 2014
    Posts:
    14
    I am trying to pass a program c to c#, and it works in c, that's not the problem, the problem I think is unity + c # + pointers, but I do not see it
     
  4. ptr0x

    ptr0x

    Joined:
    Dec 9, 2013
    Posts:
    54
    Why don't you just return array[0]? You do not need to use pointers to implement this function. Also there are syntaxical and logical errors in your code and you can't access the address of a managed object.

    Read something about the fixed statement, probably this will solve your problem (although the "problem" isn't clear to me).

    EDIT: Have in mind that using unsafe code your game will not be buildable to a lot of platforms Unity offers.
     
  5. Kainanteh

    Kainanteh

    Joined:
    Sep 3, 2014
    Posts:
    14
    In line 26 I want to spend the position memory array (int) not the position [0] array.

    This is part of a program, so YES I need pointers (if you know do whitout pointers tell me).

    Where are the syntaxical and logical errors?

    The problem is written above, not compile (with compilation error is up too).
     
  6. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190