[Solved]Steam access for Run Project(F6)

Hi there! Have a nice day!

I was looking at Steamworks4j and i success display my steam nick on the screen but i had to clean and build my project for start steam with myproject. Because the .exe and steam_appid.txt have to be same place. By the way, I am not registered user on steamworks so i dont have any app ID so, i use spacewar appid for test (480),

Here is my codes;

Main;

    package steamtest;

    import com.jme3.app.SimpleApplication;
    import com.jme3.app.state.AppState;
    import com.jme3.font.BitmapText;
    import com.jme3.renderer.RenderManager;

    /**
     * This is the Main Class of your Game. You should only do initialization here.
     * Move your Logic into AppStates or Controls
     * @author normenhansen
     */
    public class Main extends SimpleApplication {
        
        BitmapText steamNick;
        AppState steamAppState = new SteamAppState();

        public static void main(String[] args) {
            Main app = new Main();
            app.start();
        }

        @Override
        public void simpleInitApp() {
            stateManager.attach(steamAppState);
            guiNode.detachAllChildren();
            steamNick = new BitmapText(guiFont,false);
            steamNick.setSize(guiFont.getCharSet().getRenderedSize());
            steamNick.setLocalTranslation(settings.getWidth() / 2 - steamNick.getLineWidth()/2, settings.getHeight() / 2 + steamNick.getLineHeight()/2, 0);
            guiNode.attachChild(steamNick);
        }

        @Override
        public void simpleUpdate(float tpf) {
            steamNick.setText(stateManager.getState(SteamAppState.class).getName());
        }

        @Override
        public void simpleRender(RenderManager rm) {
            
        }
    }

SteamAppState;

package steamtest;

import com.codedisaster.steamworks.SteamAPI;
import com.codedisaster.steamworks.SteamException;
import com.codedisaster.steamworks.SteamFriends;
import com.codedisaster.steamworks.SteamFriendsCallback;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;

/**
 *
 * @author rhl
 */
public class SteamAppState extends BaseAppState{

    private SteamFriendsCallback steamFriendsCallback;
    private SteamFriends steamFriends; 
    
    @Override
    protected void initialize(Application app) {
        try {
            if (!SteamAPI.init()) {
                // Steamworks initialization error, e.g. Steam client not running
            }
        } catch (SteamException e) {
            // Error extracting or loading native libraries
        }   
    }
    
    @Override
    protected void onEnable() {
        if(SteamAPI.isSteamRunning()) {
            steamFriendsCallback = new MySteamFriendsCallback();
            steamFriends = new SteamFriends(steamFriendsCallback);
        }
        
    }
    
    @Override
    public void update(float tpf){
        if(SteamAPI.isSteamRunning()) {
            SteamAPI.runCallbacks();
        }
    }

    @Override
    protected void onDisable() {
        if(SteamAPI.isSteamRunning()) {
            steamFriends.dispose();
        }
    }
    
    @Override
    protected void cleanup(Application app) {
        if(SteamAPI.isSteamRunning()) {
            SteamAPI.shutdown();
        }
    }
    
    public String getName(){
        if(SteamAPI.isSteamRunning()) {
            if(steamFriends != null){
                String name = steamFriends.getPersonaName();
                return name;
            }
        }
        return null;
    }
}

and here is the my question :innocent:

How can i access steam interface in my game without clean and build, so i mean if i press the F6 key on sdk, the steam_appid.txt where should be that to steaam initialize?

----update----

steam_appid.txt should be on project root, near the master-application.jnlp.

1 Like

steam_appid.txt should be in your run directory. No idea where that is by default in sdk though.