Subscript indices must either be real positive integers or logicals.

1 view (last 30 days)
Im trying to create a mario game and am coming across the error mentioned above on this line:
if (handles.Template(Row,Column) == 0);
The rest of the code is shown below:
[Rows Columns Color] = size(handles.Template)
for RowIndex = 1:1:Rows
for ColumnIndex = 1:1:Columns
if handles.Template(RowIndex, ColumnIndex, 2) <= 22 &&...
handles.Template(RowIndex, ColumnIndex, 3) <= 24
handles.Template(RowIndex,ColumnIndex,:) == 1;
else
handles.Template(RowIndex,ColumnIndex,:) == 0;
end
end
end
configurePin(a,'A0','AnalogInput')
CurrentX = 0;
for time = [1:1:10000];
A2Voltage = readVoltage(a, 'A0');
if A2Voltage >= 3
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)+15)/29);
set(handles.SpriteAxis,'xdir','normal')
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','on');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','off');
set(I,'visible','on');
axis off
if (handles.Template(Row,Column) == 0);
handles.SpriteAxis.Position(1) = handles.SpriteAxis.Position(1)+15;
end
elseif A2Voltage < 2
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)-15)/29);
set(handles.SpriteAxis,'xdir','reverse')
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','on');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','on');
set(R,'visible','off');
set(I,'visible','off');
axis off
pause(.04)
set(M,'visible','off');
set(A,'visible','off');
set(R,'visible','off');
set(I,'visible','on');
axis off
if (handles.Template(Row,Column) == 0)
handles.SpriteAxis.Position(1) = handles.SpriteAxis.Position(1)-15;
end
end
end

Accepted Answer

Jan
Jan on 18 Jul 2017
What is your question?
You have to use the debugger to find the reason of the problem. The indices are defined here:
Row = floor(handles.SpriteAxis.Position(2)/29);
Column = floor((handles.SpriteAxis.Position(1)+15)/29);
Obviously at least one of them is not positive. You can test this easily by letting Matlab stop at the error:
dbstop if error
or use the corresponding menu in the editor. Then run the code again until it stops at the error. Now check the values of Row and Column.
for time = [1:1:10000];
to the faster and nicer
for time = 1:10000
  11 Comments
Walter Roberson
Walter Roberson on 21 Jul 2017
If there are no "hot spots" on the sprites (places that should act differently -- e.g., does it matter whether it is Mario's foot that touches the rope compared to Mario's hand?) then it is easiest to use the centroid of the sprite as the reference point, as then the distance left and right would be the same. This does have a small challenge if the sprite is an odd number of pixels in width: you should be conscious of whether the reference point is the center of the pixel or the left edge or the right edge of the pixel.
Curtis Vannor
Curtis Vannor on 21 Jul 2017
Edited: Curtis Vannor on 21 Jul 2017
Im not really sure what you mean by converting between the coordinate systems. I made this function:
function [ new_coordinates ] = coortrans( in1,in2 )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
size(in1)/size(in2)
end
Which gave a ratio of the size of the larger stage to the template, but what do I do from here?
Also, will the centroid be necessary since the sprite is its own axis? Couldn't I just use the position parameter of the axis itself?

Sign in to comment.

More Answers (0)

Categories

Find more on Video games in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!