0

Java / C#のバックグラウンドから来たMELサイトは、私が慣れていないためか、少しがっかりしましたが、一部のAPIサイトほど明確ではないと思いました。

名前を付けて保存、ファイルの名前変更、保存サイクルを自動化するMELコマンドを作成しようとしています。これを行うスクリプトがすでにあるはずですが、私も自分自身を学びたかったのです。

最初に、ユーザーがシェルフからユーザー定義のボタンをクリックし、現在のシーン名がプリロードされたプロンプトダイアログと[名前を付けて保存]ボタンと[キャンセル]ボタンを用意します。名前の変更と保存は問題ありません。エラーが発生し始めたのは、関数に分離することです(関数とプロシージャに違いはありますか?)。

string $sceneName_new;


// Initiates the scene saving, checking filename meets standards
proc saveSceneAs() {

    string $sceneName_old = `file -q -sceneName`;
    string $result = `promptDialog 
        -title "Save scene as"
        -message "Scene name:"
        -button "Save" -button "Cancel"
        -text $sceneName_old
        -defaultButton "Save" -cancelButton "Cancel"
        -dismissString "Cancel"`;

    if ($result == "Save") {
        $sceneName_new = `promptDialog -query -text`; // get result
        $sceneName_new = strip($sceneName_new); // clean whitespace (start/end)

        // check length of new name has at least one character
        if (size($sceneName_new) < 1) {
            print("Error: file name must contain at least one character. File not saved.\n");
        } else if ($sceneName_old == $sceneName_new) {
            confirmOverwriteOkay();
        } else {
            // good to save :D
            saveScene($sceneName_new);
        }
    } else {
        print("Cancelled. File not saved.\n");
    }   
}

// Asks user in case of unchanged filename, if okay to overwrite
proc confirmOverwriteOkay() {
    string $overwriteConfirm = `promptDialog 
                -title "Warning"
                -message "Are you sure you want to overwrite the current file?"
                -text $sceneName_new;
                -button "Yes, overwrite" -button "No, rename" -button "No, cancel"
                -defaultButton "No, rename" -cancelButton "No, cancel"
                -dismissString "No, cancel"`;

    if ($overwriteConfirm == "Yes, overwrite") {
        saveScene($sceneName_new);
    } else if ($overwriteConfirm == "No, rename") {
        // go back and try again
        saveSceneAs();
    } else {
        print("Cancelled. File not saved.\n");
    }
}


// Saves the scene with the given file name
proc saveScene(string $nameToSave) {
    // TODO: rename, save file
    print("File saved: " + $nameToSave);
}


saveSceneAs();    

そしてエラー:

// Error: -text $sceneName_new; // 
// Error: "$sceneName_new" is an undeclared variable. // 
// Error: -button "Yes, overwrite" -button "No, rename" -button "No, cancel" // 
// Error: Syntax error // 
// Error: saveScene($sceneName_new); // 
// Error: "$sceneName_new" is an undeclared variable. // 
4

2 に答える 2

0

これを解決するには、グローバルキーワードをsceneName_new変数に追加し、呼び出された関数での使用を宣言します。これにより、プロシージャは新しいローカル変数を作成するのではなく、そのグローバル変数を使用するようになります。

global string $sceneName_new;

// Asks user in case of unchanged filename, if okay to overwrite
proc confirmOverwriteOkay() {

global string $sceneName_new;       
string $overwriteConfirm = `promptDialog 
                -title "Warning"
                -message "Are you sure you want to overwrite the current file?"
                -text $sceneName_new;
                -button "Yes, overwrite" -button "No, rename" -button "No, cancel"
                -defaultButton "No, rename" -cancelButton "No, cancel"
                -dismissString "No, cancel"`;

    if ($overwriteConfirm == "Yes, overwrite") {
        saveScene($sceneName_new);
    } else if ($overwriteConfirm == "No, rename") {
        // go back and try again
        saveSceneAs();
    } else {
        print("Cancelled. File not saved.\n");
    }
}
于 2011-04-11T10:09:01.087 に答える
0

$sceneName_new変数定義でグローバルキーワードを使用する必要があります。また、グローバル変数を使用するすべてのプロシージャでグローバル変数を指定する必要があります。

global string $sceneName_new;

proc saveSceneAs() 
{
    global string $sceneName_new;
    //content
}

proc confirmOverwriteOkay() 
{
    global string $sceneName_new;
    //content
}
于 2013-04-12T12:26:26.597 に答える