Jump to content
  • Advertisement

Adehm

Member
  • Content Count

    54
  • Joined

  • Last visited

Community Reputation

218 Neutral

About Adehm

  • Rank
    Member
  1. Thanks a bunch cmac you lead me to the solution. This video explains it wonderfully for anyone else who would like to know how to add data to the stream. Kinda weird how you have to drag the script from a component to make it observable; didn't find a way to just do it manually through the control as it only allows me to select a gameobject and by default it's transform.
  2. Yeah I can’t get it to work. Was hoping someone would be able to get me a simple example of either making a stream or just adding to a stream before its sent and receiving it. Tried several different ways and can’t get anything to work even in the rare cases that I can write what I’m told without error it just wont do anything.
  3. I was wondering if anyone knew how to simply send and receive an integer? if (PhotonNetwork.isMasterClient) { //send an integer } If(!PhotonNetwork.isMasterClient){ //receive integer }
  4. Adehm

    C++ class variables

    Thanks for the info King Mir, very helpful; also lead me to some syntax showing me how to initialize the array in the declare which i'm very glad to know.  void af(std::array<int, 3>& n){ cout << n[1] << endl; //print second value n[1] = 3; //change second value } int main(){ std::array<int, 3> n{0,0,0}; //declare a std::array and initialize n[1] = 2; //update second value af(n); //pass it by reference cout << n[1]; //print updated value return 0; }
  5. Adehm

    C++ class variables

    Cool beans, didn't know how to pass a struct by reference like that. I'll try replacing my code tomorrow to do it that way so I can ensure I understand how; only really my second day using c++ so didn't really know how to do anything. Thanks for the examples.   In case anyone else is wondering how to pass a struct by reference here is a working example.This makes it extremely easy to refer to a group of variables with a single pass. struct board { int n = 0; }; void af(board& b){ cerr << b.n << endl; //print n proving it was updated in main b.n = 2; //update n } int main() { board b; //instance of struct board b.n = 1; //update n af(b); //pass instance of structure by reference to another function cerr << b.n; //print n proving it was updated from af() return 0; }
  6. Adehm

    C++ class variables

    Problem with pointers or references as I understand it; is passing a multi dimensional variable. From what I understand is I can't pass that all through one variable, though I could be wrong. I was working on this: http://www.hackerrank.com/challenges/battleship1p and just wanted to be able to call functions to return a bool based on other data. Then instead of returning two pieces of data, which I don't know how to do, I could just set global variables from that function. Here is what I did to solve this problem; though I got a bad score because I don't know a better way of searching the board besides sequential until I find a target. #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> namespace board { //Put all of your global variables here int n = 0; int xy[10][10]; //integer data repersenting board 0 = miss or dead/1 = undiscovered/2 = hit int hX = 0; int hY = 0; } using namespace std; //------------------------------------------------------------------------------------------------------- bool hit(int x, int y){ //search for another hit/ y-1,y+1,x-1,x+1 if(y - 1 > -1 && board::xy[x][y-1] == 2){ //found board::hX = x; board::hY = y-1; return true; }else if(y + 1 < board::n && board::xy[x][y+1] == 2){ //found board::hX = x; board::hY = y+1; return true; }else if(x - 1 > -1 && board::xy[x-1][y] == 2){ //found board::hX = x-1; board::hY = y; return true; }else if(x + 1 < board::n && board::xy[x+1][y] == 2){ //found board::hX = x+1; board::hY = y; return true; } return false; } //------------------------------------------------------------------------------------------------------- bool attack(int x, int y){ //search for another hit/ y-1,y+1,x-1,x+1 if(y - 1 > -1 && board::xy[x][y-1] == 1){ //found board::hX = x; board::hY = y-1; return true; }else if(y + 1 < board::n && board::xy[x][y+1] == 1){ //found board::hX = x; board::hY = y+1; return true; }else if(x - 1 > -1 && board::xy[x-1][y] == 1){ //found board::hX = x-1; board::hY = y; return true; }else if(x + 1 < board::n && board::xy[x+1][y] == 1){ //found board::hX = x+1; board::hY = y; return true; } return false; } //------------------------------------------------------------------------------------------------------- int main() { cin >> board::n; string col; int hX = -1; int hY = -1; for(int y = 0;y<board::n;y++){ cin >> col; int x = 0; for(char& c : col) { switch(c){ case 'm' || 'd': board::xy[x][y] = 0; break; case '-': board::xy[x][y] = 1; break; case 'h': board::xy[x][y] = 2; //store hit hX = x; hY = y; break; } x=x+1; } } //board now stored in xy //if hX a positive number then search around it if(hX > -1){ //search for another hit if(hit(hX,hY)){ //another hit found int dirX = 0; int dirY = 0; //direction known from hX - xy.hX or similier //find direction //cerr << hX << " <> " << board::hX << endl; if(hX > board::hX){ //x-1 dirX = -1; }else if(hX < board::hX){ //x+1 dirX = 1; }else if(hY < board::hY){ //y-1 dirY = -1; }else if(hY > board::hY){ //y+1 dirY = 1; } //check direction until = 1 for(int i = 1;i<5;i++){ if(board::xy[hX+dirX*i][hY+dirY*i] == 1){ //found next attack hX = hX+dirX*i; hY = hY+dirY*i; break; } } }else{ //try around it until hit if(attack(hX,hY)){ hX = board::hX; hY = board::hY; } } }else{ //find a 1 to attack for(int y = 0;y<board::n;y++){ for(int x = 0;x<board::n;x++){ if(board::xy[x][y] == 1){ //attack cout << y << " " << x; return 0; } } } } cout << hY << " " << hX; return 0; }
  7. Adehm

    C++ class variables

    I can do it with global variables. namespace ObjectGlobalVars { //Put all of your global variables here int n = 0; } using namespace std; int anotherFunction(){ return ObjectGlobalVars::n; } int main() { ObjectGlobalVars::n = 10; cout << anotherFunction(); return 0; }
  8. Adehm

    C++ class variables

    Is there a way I can have a place that holds variables that all my functions can share and change?
  9. I'm new to C++ and a bit confused on how to use public variables.   I create a class: class board{ public: int n = 0; }; Then I manipulate it in main: int main() { board xy; xy.n = 10; cout << anotherFunction(); return 0; } It would seem that only in main does n = 10; What I want to do is update it in the class so another function can use it. Is that possible? And if so how can I accomplish that? int anotherFunction(){ board xy; return xy.n; //need it to equal 10 now not 0 sense main updated it } Hope this makes sense. Thanks.
  10. Got it working. Put a C# script in the Editor folder and paste this code. This will close all scenes currently loaded in the Hierarchy when the play button is clicked. using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.SceneManagement; using System.Collections; [InitializeOnLoad] class Editor { static Editor () { EditorApplication.playmodeStateChanged += PlaymodeStateChanged; } private static void PlaymodeStateChanged(){ if (!EditorApplication.isPlaying) { for (int i = 0; i < EditorSceneManager.sceneCount; i++) { Scene scene = EditorSceneManager.GetSceneAt (i); Debug.Log (scene.name); Debug.Log (EditorSceneManager.CloseScene (scene, false)); } } } }
  11. Only used for unloading the compiled scenes the game is running; not the editor Hierarchy.
  12. Yeah, the function works that way so I guess it can't be done off the play button because there doesn't appear to be a way to intercept it soon enough or override it altogether. I'll post a solution if I find one, thanks for the help.
  13. How to run it from MenuItem?   Would return false if the scene name didn't exist.   No, starts paused for testing.
  14. Unity C#   Trying to close a scene from the Hierarchy when a user clicks play in the editor. It returns True but the scene remains open. [InitializeOnLoad] class EditorClass : Editor{     static EditorClass(){         //user clicks play         if (EditorApplication.isPlayingOrWillChangePlaymode) {             //remove a scene             Debug.Log(EditorSceneManager.CloseScene(EditorSceneManager.GetSceneByName(sceneName),false));         }     } }
  15. Adehm

    Wills and Wonders

    Wills and Wonders is now available on the steam store for early release. Follow the link below or give us a search on your steam client. Thank you for the support and we hope you enjoy the game. http://store.steampowered.com/app/513060/
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!