RNG to pull scripts

3 ビュー (過去 30 日間)
Jayvion Rolland
Jayvion Rolland 2020 年 12 月 10 日
コメント済み: Rik 2020 年 12 月 14 日
I'm creating a game that invoves using a random number generator to decide which .m script to pull from a set of files. I run into two errors mainly, (Error using fileparts (line 58) Input must be a row vector of characters, or a string scalar, or a cellstr, or a string matrix.) and (Error in run (line 40) [fileDir,script,ext] = fileparts(scriptname);)
I would like the scipt to run the functions itself at random, but the errors break the while loop I was attempting to run them in. Does anyone know what I may be doing incorrectly?

回答 (1 件)

Anmol Dhiman
Anmol Dhiman 2020 年 12 月 14 日
Hi Rolland,
Just pass the file name as character vector as shown below.
run('Riddle_1');
Hope it helps
Anmol Dhiman
  1 件のコメント
Rik
Rik 2020 年 12 月 14 日
Or:
run(scriptname)
An even better strategy would be to convert the scripts into a function that returns a struct array. That way you can use this:
this_riddle=all_riddles_struct(randi(end)); % select 1 riddle
which will not require any modification if you decide to add or remove riddles from your database function.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by