I want to know how can a setup a button for switch the renderable properties beetwen on and off.
Using the maxscript listener I can do one or another, but I can't make a script that change beetwen them
$.renderable = off
$.renderable = on
And this also works:
if $.renderable = on then $.renderable = off
But I don't understand why the opposite doesn't:
if $.renderable = off then $.renderable = on
I also tried this but no luck either.
if $.renderable = on then $.renderable = off
else $.renderable = on
'=' is assignment, that's why your second example doesn't work, for comparison you'd use '==' instead. If you have a single object selected, the easiest way to toggle the state is
$.renderable = not $.renderable
Related
I am very new to coding and I'm still trying different languages out, I started off with GameMaker Studio and changed to Godot due to its compatibility with Mac I might as well learn something newer since GameMaker has been out for quite some time.
I want to create a RPG game and apply animation to each direction the character moves but the animation only plays after the key is pressed AND lifted. This means that while my key is pressed, the animation stops, and the animation only plays while my character is standing still, which is the complete opposite of what I want. The script looked really straight forward, but doesn't seem to be working.
I would tag this as the GDScript language instead of Python, but I guess I'm not reputable enough to make a new tag, so I tagged it under python because it is the most similar.
#variables
extends KinematicBody2D
const spd = 100
var direction = Vector2()
var anim_player = null
func _ready():
set_fixed_process(true)
anim_player = get_node("move/ani_move")
#movement and sprite change
func _fixed_process(delta):
if (Input.is_action_pressed("ui_left")) :
direction.x = -spd
anim_player.play("ani_player_left")
elif (Input.is_action_pressed("ui_right")):
direction.x = spd
anim_player.play("ani_player_right")
else:
direction.x = 0
if (Input.is_action_pressed("ui_up")) :
direction.y = -spd
anim_player.play("ani_player_up")
elif (Input.is_action_pressed("ui_down")):
direction.y = (spd)
anim_player.play("ani_player_down")
else:
direction.y = 0
if (Input.is_action_pressed("ui_right")) and (Input.is_action_pressed("ui_left")):
direction.x = 0
if (Input.is_action_pressed("ui_up")) and (Input.is_action_pressed("ui_down")) :
direction.y = 0
# move
var motion = direction * delta
move(motion)
As you check the input in _fixed_process, you call anim_player.play() several times a frame, which always seems to restart the animation, and thus, keeps the very first frame of the animation visible all the time.
As soon as you release the key, anim_player.play() stops resetting the animation back to start, and it can actually proceed to play the following frames.
A simple straight-forward solution would be to remember the last animation you played, and only call play() as soon as it changes.
You need to know if the animation has changed
First you need to put these variables in your code:
var currentAnim = ""
var newAnim = ""
And then you add this in your _fixed process:
if newAnim != anim:
anim = newAnim
anim_player.play(newAnim)
To change the animation you use:
newAnim = "new animation here"
I have created a Gui in matlab which has three axes and i would like to change the scale to log and linear by right click on the particular figure and select the scale options(1.logarithmic 2.linear). I tried using the UIcontextmenu. But i didn't get the result.
firstcycle_mass = handles.Data1{1,1}(1:6392,1);
firstcycle_ioncurrent = handles.Data1{1,2}(1:6392,1);
replace_with_dot_firstcycle_mass = strrep(firstcycle_mass, ',','.');
X1 = str2double(replace_with_dot_firstcycle_mass);
replace_with_dot_firstcycle_ioncurrent = strrep(firstcycle_ioncurrent, ',','.');
Y1 = str2double(replace_with_dot_firstcycle_ioncurrent);
axes(handles.axes1);
plotline= plot(X1,Y1,'r');
xlabel('Mass [amu]');
ylabel('Ion current [A]');
c=uicontextmenu;
plotline.UIContextMenu = c;
% Create menu items for the uicontextmenu
m1 = uimenu(c,'Label','logarithmic','Callback',#setlinestyle);
m2 = uimenu(c,'Label','linear','Callback',#setlinestyle);
function setlinestyle(source,callbackdata)
switch source.Label
case 'logarithmic'
set(gca,'yscale','log')
case 'linear'
set(gca,'yscale','linear')
end
end
I am trying to create an animation to make it look like a button turns over and the back shows. So what I was trying to do is:
1- Show a button with BackgroundColor x. (The button now has a Width of null, the property ActualWidth does have a value.)
2- Create a double animation that changes the width of the button to zero.
DoubleAnimation widthAnimation = new DoubleAnimation();
widthAnimation.From = this.ActualWidth;
widthAnimation.To = 0;
widthAnimation.SpeedRatio = 3;
widthAnimation.Duration = TimeSpan.FromMilliseconds(800);
3- Change the BackgroundColor of the button.
ColorAnimation colorAnimation = new ColorAnimation();
colorAnimation.From = State ? _xColor : _yColor;
colorAnimation.To = State ? _yColor : _xColor;
colorAnimation.BeginTime = TimeSpan.FromMilliseconds(400);
colorAnimation.Duration = TimeSpan.Zero;
4- Change the width back to it's original value.
widthAnimation.AutoReverse = true;
The problem is when the animation runs twice the animation reads this.ActualWidth while animating, which causes it to fail to the original width. How can I solve this? I would like to set the Width back to null again, but it seems impossible to me.
You'd better use xaml style and template to "declare" what you want and let WPF/Silverlight take care of all.
If you try to do the same thing by code you can do it but you need to know what the framework does behind the scenes.
Basically you can set
- Style to define the values of some properties of the control
- DataTemplate to define the visual representation of the control's content
- ControlTemplate to define the appearance of the control
Each of those can have Triggers
- Property Triggers
to set properties or starts actions, such as an animation
when a property value changes or when an event is raised;
EventTriggers and Storyboards
to start a set of actions based on the occurrence of an event
If you like to learn about XAML Style and Template,
take a look at http://msdn.microsoft.com/en-us/library/ms745683.aspx
Spend a day to learn and save many hours (or days) of try and error and frustration!
To go right to the point, in your case I think you should use a Storyboard.
See http://msdn.microsoft.com/en-us/library/ms742868.aspx
where you can find also the code equivalent of XAML examples
I came to the idea to targetting the MaxWidth instead of the actual Width. I now use a KeyFrameCollection which sets the MaxWidth to int.MaxValue at the start (so also at the end when using autoreverse).
It will work fine untill there will be phones with a resolution bigger than the max int value.
The code:
DoubleAnimationUsingKeyFrames widthAnimation = new DoubleAnimationUsingKeyFrames();
widthAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame()
{
KeyTime = TimeSpan.Zero,
Value = int.MaxValue,
});
widthAnimation.KeyFrames.Add(new LinearDoubleKeyFrame()
{
KeyTime = TimeSpan.FromMilliseconds(1),
Value = ActualWidth,
});
widthAnimation.KeyFrames.Add(new LinearDoubleKeyFrame()
{
KeyTime = TimeSpan.FromMilliseconds(400),
Value = 0,
});
widthAnimation.Duration = TimeSpan.FromMilliseconds(400);
widthAnimation.AutoReverse = true;
var scin = new Scintilla();
ScintillaHotspotStyle = scin.Styles.LastPredefined.Index + 1;
scin.Margins[0].Width = 20;
scin.Caret.HighlightCurrentLine = true;
scin.Styles[ScintillaHotspotStyle].IsHotspot = true;
scin.Styles[ScintillaHotspotStyle].Underline = true;
scin.Styles[ScintillaHotspotStyle].ForeColor = System.Drawing.Color.Blue;
var contents = File.ReadAllText(file);
scin.Text = contents;
//scin.ConfigurationManager.Language = "cpp";
//scin.ConfigurationManager.Configure();
scin.GetRange(2, 5).SetStyle(ScintillaHotspotStyle);
//scin.ConfigurationManager.Language = "cpp";
//scin.ConfigurationManager.Configure();
It doesn't matter which order of the commented lines, nor if the call to .Configure() is performed - the outcome is the same:
If however, I do not apply the syntax highlighting, it does work:
Scintilla is pretty confusing, so I'm probably doing something wrong - but I'm not sure what...
I think that the syntax hiliting is applied after your job.
Or like if you read the scintilla documentation it seems than hotspot style have restricted feature.
"""
Caret, selection, and hotspot styles
The selection is shown by changing the foreground and/or background colours. If one of these is not set then that attribute is not changed for the selection. The default is to show the selection by changing the background to light gray and leaving the foreground the same as when it was not selected. When there is no selection, the current insertion point is marked by the text caret. This is a vertical line that is normally blinking on and off to attract the users attention.
"""
Did you try to force the style hiliting in an area which are not syntactically hilited ?
Near main or print as an example.
And try it by setting a background color.
I have such code:
a=5;
b=a;
c=10;
u = (0:0.05*pi:2*pi)'; %'
v = [0:0.05*pi:2*pi];
X = a*sin(u)*cos(v);
Y = a*sin(u)*sin(v);
Z = c*cos(u)*ones(size(v));
Z(Z>0)=0; % cut upper
V1=4/3*pi*a*b*c;
d=1/2;
e=2^d;
a2=a/e;
b2=a/e;
c2=c;
V2=4/3*pi*a2*b2*c2;
X2 = a2*sin(u)*cos(v);%-2.5;
Y2 = b2*sin(u)*sin(v);
Z2 = c2*cos(u)*ones(size(v));%+0.25;
Z2(Z2>0)=0; % cut
h=1/3;
for j = 1:20
k1=(sin(pi*j/20)+0.5)^h;
a=a*k1;
c=c*k1;
X = a*sin(u)*cos(v);
Y = a*sin(u)*sin(v);
Z = c*cos(u)*ones(size(v));
Z(Z>0)=0;
a2=a2*k1;
b2=a2*k1;
c2=c2*k1;
X2 = a2*sin(u)*cos(v)+5;%-2.5;
Y2 = b2*sin(u)*sin(v);
Z2 = c2*cos(u)*ones(size(v));%+0.25;
Z2(Z2>0)=0;
hS1=surf(X,Y,Z);
alpha(.11)
hold on
hS2=surf(X2,Y2,Z2);
hold off
axis([-20 20 -20 20 -20 20]);
F(j) = getframe;
end
movie(F,4)
I have to input parameters a,b,c from the keyboard. I've made GUI & tried to do it by using "Edit text" with a function below, but it's not working((.
I can't understand what's the problem with it.
function a_edit_Callback(hObject, eventdata, handles)
user_entry = str2double(get(hObject,'string'));...
a=user_entry;
The problem is that your callback function executing your code is not 'seeing' the parameters you defined in your edit text callbacks. You need to establish your variables in the subfunction, since they aren't global.
Using guide, set up a uicontrol button to click when you've entered your parameters into your uicontrol edit text boxes. Under the callback of your button, place your above code, with the following at the top:
a=str2double(get(handles.a_edit,'String'));
b=str2double(get(handles.b_edit,'String'));
c=str2double(get(handles.c_edit,'String'));
This will pull in the current strings of your edit text uicontrols. (Assuming you've assigned the tag format x_edit for each of the edit text boxes in guide.)
EDIT:
Open the figure you already created with the edit text boxes. Next, check to make sure each of your text boxes have the tag a_edit, b_edit, c_edit by using the property inspector. Then create a button using guide, and open the property inspector by double clicking on it. Find the 'tag' field, and name it run. Save your figure, and open the corresponding M-file.
Next, find the line with run_Callback(hObject, eventdata, handles). Place the following under it:
a=str2double(get(handles.a_edit,'String'));
b=str2double(get(handles.b_edit,'String'));
c=str2double(get(handles.c_edit,'String'));
%# Add the rest of your code from above verbatim, minus the first three lines
This should be the ONLY code you add to the auto-generated M-file - don't mess with anything else until you get this much working. If you don't want the animation popping up randomly in your figure window, you can add a set of axes using guide as well.
From the looks of the code, it appears to be a 'script' and not a 'function'.
Did you just want a 'dialog (built-in GUI dialog)'? If so, you can add the following at the beginning of your script:
prompt = {'Enter the parameter value "a":','Enter the parameter value
"b":','Enter the parameter value "c":'};
dlg_title = 'Input the Parameter Values';
num_lines = 1;
def = {'5','5','10'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
a=answer{1};a=str2double(a);
b=answer{2};b=str2double(b);
c=answer{3};c=str2double(c);
% Y.T.